Servlets :: Shopping Cart Session Is Not Working Properly

Jan 4, 2015

I am adding my shopping cart in session like bellow in servlet

HttpSession session = request.getSession();
session.setMaxInactiveInterval(60*30); // 30 minutes
if (session.getAttribute("cart") == null){
session.setAttribute("cart", new ShoppingCart());
}
cart = session.getAttribute("cart");

I seems if more than one person accesses it from server, if they items in the shopping cart, all the product is added to a single session. I mean if i added 4 items first and other person adds 2 items, second person sees 6 products in his cart. Where am I going wrong?

View Replies


ADVERTISEMENT

Servlets :: Shopping Cart - Not Add More Than One Item

Dec 30, 2014

I have following servlet to add items into cart -

import java.io.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.RequestDispatcher;

[Code]...

One item gets added to the cart successfully. When adding the second item it gives a Null Pointer Exception at line 53

cart.add(item);

View Replies View Related

Servlets :: How To Remove Item From Shopping Cart

Feb 20, 2014

I created a website using jsp and servlet. I made a shopping cart and got the items to display. But how can i remove the items from the cart? Next to each item is a remove button. When that is pressed the item selected needs to be removed and cart needs to refresh.

Here is the code to display the cart:

<table width='700' border='2'>
<tr>
<td>Qty</td>
<td>Name</td>
<td>Price</td>

[Code] .....

View Replies View Related

Servlets :: Shopping Cart - Show Text Based On Which Page A User Is Coming From

May 30, 2014

I am making a shopping cart app in JSP and servlets to bring it all together. Finally.

I have a registration servlet (c1), a registration form jsp (c2), a login jsp (c3). c1 checks if a username is in the database or not.

If the username is not there, then register the user and send them to c3. I want c3 to display a "registration successful" message if a user has just registered successfully and is coming from c1. ELSE, take the user back to c2 with a message which tells them to choose a different username or password etc.

How do I implement the logic of showing a message depending on where a user is coming from ? The servlets and jsps are ready and I only need to add this logic for a custom message. Of course, I could make a JSP for Registration Successful and one for Registration Failure. But, that seems to be unnecessary.

View Replies View Related

Shopping Cart Using Array Of Items

Nov 5, 2014

I am working on a project. It is a shopping cart java program that should be setup with an array size of 5 and increased at increments of 3 if you go over 5 items. When I go over 5 items in increases however it changes the item names to null. See output below.

Here is the actual assignment:

In this exercise you will complete a class that implements a shopping cart as an array of items. The file Item.java contains the definition of a class named Item that models an item one would purchase. An item has a name, price, and quantity (the quantity purchased). The file ShoppingCart.java implements the shopping cart as an array of Item objects.

1.Complete the ShoppingCart class by doing the following:

a.Declare an instance variable cart to be an array of Items and instantiate cart in the constructor to be an array holding 5 Items.
b.Fill in the code for the increaseSize method. Your code should be similar to that in the CDCollection class handout but instead of doubling the size just increase it by 3 elements.
c.Fill in the code for the addToCart method. This method should add the item to the cart and update the totalPrice instance variable (note this variable takes into account the quantity).
d. Add a getTotalPrice() method to return the totalPrice.
e..Compile your class.

2.Write a program that simulates shopping. The program should have a loop that continues as long as the user wants to shop. Each time through the loop read in the name, price, and quantity of the item the user wants to add to the cart. After adding an item to the cart, the cart contents should be printed along with a subtotal. After the loop, print a "Please pay ..." message with the total price of the items in the cart. Compile and run this class.

OUTPUT

Enter the name of the item: Apples
Enter the unit price: .5
Enter the quantity: 1

Shopping Cart

ItemUnit PriceQuantityTotal
Apples$0.501$0.50
Total Price: $0.50
Continue shoppping (y/n)?
y
Enter the name of the item: Oranges
Enter the unit price: .5
Enter the quantity: 1

[Code] .....

View Replies View Related

JSP :: Shopping Cart - Custom Tag And Image

Jan 4, 2015

I am developing shopping cart in which I am storing image in database and retrieving.

When I select any product category from menu. example, I selected Computer then all list of product related to computer will be return i.e productName, Price and image, By using JSON.

this is my json response and output in comment.

success : function(data) {
if (data.length != 0) {
var d = eval(data);
$("#productList").html("");
for ( var key in d) {

[Code] ....

Alternatively I created custom tag to resolve this.Custom tag is working fine in jsp but in java script it saying error raised Unterminated custom tag. I think I used this custom tag in javascript but i am not sure about this error,

custom tag code for image :
imgByte = product.getImage().getBytes(1, (int) product.getImage().length());
String encodeimage = new String(Base64.encodeBase64(imgByte));
out.println("<tr><td><img src="data:image/jpeg;base64," +encodeimage + ""/><tr> <td>");

MY Question
1 - How can I use Custom tag in javascript ? Or
2 - How can we extract image from json object, like I did in custom tag .

View Replies View Related

JSP :: Shopping Cart - Calculate Total Price

Sep 21, 2014

I am making a shopping cart web, but some problems I meet about how to calculate the total price

I use ajax in product list web and if I choose one product , it will send the Id that I read from MySql to servlet and use session to save it . and I click the button jump to the cart, the page cart.jsp will read information from session ,and find product information from mysql by id , now my question is where I calculate the total price, servlet or jsp?

View Replies View Related

Java ArrayList - Printing Shopping Cart Receipts Project

Oct 26, 2014

I'm new to the concept of ArrayList and I want to solve this problem in my code.

My main problem: I don't know how to sort itemA and itemB to appear only once then It will just add the total prices together.

This is the behavior of my code:

C:Documents and SettingsDrewDesktop>java ReceiptCode
Enter Company Name
ABC Co
Enter STREET ADDRESS
123 Main Street
Enter CITY, STATE, ZIP

[Code] ....

I don't know how to sort itemA and itemB to appear only once then It will just add the total prices together. Here is my sourcecode:

ReceiptCode.java
import java.util.Scanner;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

[Code] ....

View Replies View Related

Servlets :: Dojo Progressbar Not Working Properly With Commons FileUpload

Sep 22, 2014

I have been trying different examples on showing progress bar for file upload progress for couple of days.

Some of the different example were using libraries like Dojo,jQuery and just using plain AJAX with iframe method.

But unfortunately, however i try i'm not able to show the progressbar thingy at all although the upload part is working good.

Following is the example with Dojo[dojo-release-1.0.3]

I'm using Servlet 2.5,commons fileupload libs, TomEE-plus-1.7. 0 & ant for building tool in ubuntu 12.04 as the platform with firefox 32.

Here is the code (as it was in the site)

build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="upldEx6" basedir="." default="clean">
<!-- Properties start-->

[Code]....

If i choose a file of size 68MB, on page load the progressbar is seen but stays at 0% all the time even after submttting the form.

On debugging, cant find error/bug here.

P.S This code can be seen CodeGuru: FileUpload Example

View Replies View Related

Servlets :: Session-timeout Not Fully Working

May 9, 2014

in my web.xml my session time out is working but not fully working in my ui i use tiles , i have 5 clickable side panels i try to set timeout for 1 minute or 10 minutes for testing after the time is timeout this what happen working refresh the page after time out = working ,directed me into log in page which is correct.i have 5 clickable side panel in my page after timeout when i click the first 2 in side panel tabs it directed me into log in page which is also correct not working after the timeout when i navigate the page i click the other 3 side panels i can still navigate into the page but when i click the first 2 side panel it directed to log in page w/c is correct but can still navigate the page the other 3 side panels

issue : my session timeout is not fully working on my page.

<session-config>
<session-timeout>10</session-timeout>
</session-config>

View Replies View Related

Servlets :: Can Access Session Object Even Session Is Time Out

Jun 4, 2014

Can I access the session object even session has been expired? I need to check whether session is expired or not for each request.The session invalidation is set null the session object. What I concluded, session time out I can access session object but session invalidation I can not access session object. How can I find the session time out by using session object?

View Replies View Related

Servlets :: Updating Session Value But Same Session In JSP Page Not Updated

Jul 8, 2014

I am developing a e-commerce college project, here i add the items in the cart(a div tag in the jsp page) via servlet by creating sessions,

flow control: shopping jsp (when user wants to add an item in the cart) --> item servlet (which is used to create session and synchronized it) --> cart servlet(which is used to add items in the arraylist and show them in the shopping.jsp's div tag + it also sets the total purchase amount in the session variable "totalpurchase")

now after that user wants to proceed to checkout, here i use the onclick event to check the minimumshopping amount must be less than the totalpurchase (totalpurchase which i had setted in the session),but my jsp page is unable to rechognise the updated value of the totalpurchase, yes, if i reload the page, it rechognises the new updated value of the totalpurchase? but i want it to rechognise the updated total purchase value, without reloading he jsp page..

View Replies View Related

Servlets :: How To Design A Shopping Website

Nov 23, 2014

I am working on a Project of Ecommerce Shopping WebSite in Java.

First I Decided to use Servets,JSP,Spring,hibernate etc.. from Scratch to design its Layouts and Functionality.

But After Reading this Thread [URL]...

I Found that there are already some Ecommerece Solution that are availabale in Java Like Magento.

Is it worth To use these Ecommerce Solution for Development Purpose of Premium Purpose.

I read that some of them are Open Source.

If a ShoppingCart Solution is OpenSource then Can We Use that to develop and Distribute for Premium Purpose?

View Replies View Related

Servlets :: Architecture Design For Shopping Database

Apr 2, 2015

I'm working on a consulting training project to create a eCommerce online shopping application. Nothing big, just something functional and simple. That's why I want to structure it with the easiest maintainability possible. I've already ironed out the the database entities and how they'll relate to one another and even managed to establish connection to the database from my java application class. NOW I need to configure a user session on the web.xml, from what I've learned so far in my consulting, I can easily use jsp and servlets to have httpsession objects receive and send the information needed to and from the database, but the question is, how many do I need for a client's session?

Would maintainability be easier if I divide each entity's class actions to different servlets(a customer servlet, order servlet, product servlet, etc...), or can a single servlet handle an entire session without any complication?

View Replies View Related

OnItemLongClickListener Not Working Properly

Apr 19, 2014

I created a dialog file:

Java Code:

package com.example.classorganizer;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

[code]...

When I long click item in the list nothing happens. I get no errors at all and I believe that either I put the code in the wrong place or I missed something else that stops Dialog from starting.

View Replies View Related

JSF :: 2.2 - Not Working Properly With AJAX And File Uploads

Feb 27, 2014

I'm having problems with using the h:inputFile tag with JSF 2.2 and Glassfish 4.0 on Eclipse. The file uploads work when the enctype is set to "multipart/form-data" in the h:form tag, but AJAX will not work. When I leave out the encType (defaults to "application/x-www-form-urlencoded") AJAX works but the uploads do not work, and in fact Glassfish crashes and generates the message:

The request content-type is not a multipart/form-data

Likewise I'm having the same problems with the PrimeFaces file upload tag p:fileUpload. In a JSF 2.0 it works correctly, but with JSF 2.2 it's giving the same problems and generates the message above.

When I start up Eclipse it tells me that Mojarra 2.2.0 is installed. Is this the source of the problem, and if so, how do I install a later version of Mojarra?

View Replies View Related

JSF :: Primefaces Sorting Not Working Properly With Live Scrolling

Dec 15, 2013

I have datatable with live scrolling enabled.The columns are not getting sorted fully.When one of the columns is sorted,for example "insured" in the image shown below, all the records seem to have sorted but when i reach the end of scroll and next set of records get loaded i see other records in unsorted order as indicated in the image ,when i try to see the column in descending order.So because of this i am not getting the sorting feature accurately done(All records are not getting sorted at a single stretch)

My JSF code snippet

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lazylpId}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="15" scrollWidth="100%"
scrollHeight="75%" styleClass=".ui-datatable-hor-scroll"

[Code] ....

View Replies View Related

Mail Reading Functionality Is Not Working Properly Using POP3 Protocol

Mar 17, 2014

My Mail reading functionality is not working properly using POP3 protocol. Actually I can read the mail but the status is not changed as read.

Java Code:

public static void main(String arg[]) throws MessagingException, IOException{
String host = "pop.test.net";
String user = "test@beq.com";
String password = "abc10";
String protocol = "pop3";

[code]....

View Replies View Related

Traverse Binary Tree In Post Order - POIterator Not Working Properly

Apr 17, 2014

I have a Java Code:

POIterator mh_sh_highlight_all('java');

class that implements an Iterator.

A new instance of the Java Code:

POIterator mh_sh_highlight_all('java');

Class is supposed to traverse a binary tree in Post Order. But when I attempt to test a

Java Code: POIterator mh_sh_highlight_all('java');

Object in my main class, it doesn't work as its supposed to. I might be implementing it wrong.

Java Code:

public PostOrderIterator<E> implements Iterator<E>{
Deque<BNode<E>> somestack = new LinkedList<BNode<E>>();
BNode<E> position;
public POIterator(BNode<E>root){
somestack = new LinkedList<BNode<E>>();
somestack.push(root);}

[Code] ....

View Replies View Related

JSP :: Session Validate Is Not Working In Internet Explorer

Aug 9, 2010

I have a click button called log off , here once a user clicks it , task goes to logout servlet to end current user session . below is my code , I don't know why it works fine with mozilla firefox and google chrom but not working with internet explorer.

response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0);
HttpSession httpSession = request.getSession();

[Code] ....

here it goes fine to my index, but if I logged in again, I should enter a new session , but unfortunately this not happened in explorer , works fine with mozilla , and chroom.

I have also done in my index.jsp the check like below:

<%
if(session!=null){
session.setAttribute("validUser",null);
session.invalidate();
%>

just to erase whatever previous session . But why session exist on same page ! only in explorer , it makes me open new explorer for new user and that is what I don't want !

View Replies View Related

Servlets :: How To Use Session

Apr 16, 2014

I'm trying to go back to basic and strengthen some of my foundation. I'm wondering what kind of data would be appropriate to be stored inside a session? My app is a web app where all the users are the employee of a company. So it's an web-based app that keeps track of stock movements, purchasing and sales order (standard distributor company). The web app interacts strictly with employees, so no public facing app (yes, that's right, no shopping cart). So, in this kind of web app, what kind of data that by storing it to session.

View Replies View Related

Servlets :: Same Session On Two Separate Web Applications?

May 18, 2014

We have this website that is run on two web applications. The first web application hosts the home page and clicking certain links in the home page would forward it to pages of the second web application where certain functionalities can be done. Now, there has been an initiative to redesign the site to have a login page and only logged in users could browse it. This would mean a login page being created in the first app, and when links to the second application are clicked, the pages are supposed to forward to it with the same session of the user that logged in.

We have already creating handling to pass the session from the first app to the second. Logging out from the first application would also invalidate the same user session in the second application. My questions is, is this a bad idea? would it be better to combine the two apps even if it would mean a huge impact?

or is there are better way to do this? like set it in web.xml. I have read that you cannot use two context for it.

View Replies View Related

Servlets :: Cannot Serialize Session Attribute

Jan 11, 2015

I am getting following exception.

Jan 11, 2015 10:08:23 PM org.apache.catalina.session.StandardSession writeObject
WARNING: Cannot serialize session attribute cart for session 2F9FF7A5ABC3620BD5B3BC0C4D46C558
java.io.NotSerializableException: org.apache.tomcat.jdbc.pool.DisposableConnectionFacade
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)

[Code] .....

View Replies View Related

Servlets :: Getting Data Anywhere By Storing In Session

Jul 22, 2014

I've sample code of jsp and servlets. Below is my code.

Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="AnnotationServlet">

[code]....

Now I want to store those username and age(in .html) somewhere and I want those information in welcome.jsp. Now, I'm storing all those in session itself(In doGet method(servlet)).

2 Doubt) Also, when I get the session in servlet HttpSession session = request.getSession(); line No. 27. The session value is org. apache. catalina. session. StandardSessionFacade@69a8bf4f...I'm expecting that session is to be empty. Because, I dint store anything until that line.

View Replies View Related

Servlets :: Why Objects Stored In Session Should Be Serializable

Feb 5, 2015

Why is it that objects stored in session object should be serializable?

View Replies View Related

Servlets :: Restoring Session Variable After Timeout

Oct 17, 2014

My application uses Struts and IBM Web application Server. I have a question regarding session management. I have a variable stored in session scope, i.e. the name of the client. it is a intranet application. Now whenever the user leaves the browser screen for a long time, the session times out and losses the name of the client.

How to restore the variable after the client comes back and starts using the browser and refreshes the screen and starts using the application. I want just the browser to remember the session variable i.e. "name" of the client.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved