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
ADVERTISEMENT
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
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
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
View Related
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
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
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
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
Sep 26, 2014
String name = "Aaron";
String whatToChange = "name";
String verifyNameChange = "";
boolean changeName = false;
if(whatToChange.equals("name")){
while(!changeName){
[Code] ....
I've been working on a small text-based RPG for fun. This particular part is supposed to allow the user to change their name. Now, the problem is that when they reach the option to change their name, the above code seems to skip the line:
name = scan.nextLine();
It will erase whatever the player previously entered for their name, as well. So it will print out:
Okay, let's change your name. What did you say it was? Alright, so you'll go by . Is that correct? [now allows input for verifyNameChange]
The above code works fine on it's own, but somehow messes up when put into the full program. I don't want to post the whole program, because it's fairly large. But the String name is set and functions fine before this bit of code.
View Replies
View Related
Nov 20, 2014
I have list of employees in my database and their associated information like employeeId,supervisor and process. I have class named EmployeeDetails having same properties. I am fetching details of all users using below code:
<%EmployeeDetails employeeList;
employeeList=(List<EmployeeDetails>)assetmain2.getEmployeeList(loginName);%>
<table>
<tr>
<td>
Requested For <select name="requestedForName" id="requestedForNameID">
<option selected="selected">--Select--</option>
<%int i=0;
[Code] .....
In employeeList, we have list of objects having data of employees. I donot know how to get which object is selected in dropdown and based on that rest of the text fields are populated. Example:
Name ID Supervisor
-------------------------------------------------------
Pawan Kumar3033045Vimal Kumar
Vimal Kumar3040901Dinesh Hemrajani
If Pawan Kumar is selected from dropdown then '3033045' and 'Vimal Kumar' should get populated.
View Replies
View Related
May 8, 2014
I have a basic html form with one user input text box labeled "Enter a number" and a submit button labeled "Create a multiplication table". This is the working with a servlet to display an html formatted multiplication table. Everything else is working fine just the formatting is off; I can't seem to get the top row and far left column to number properly. It should look like this with the top row of numbers beginning with a blank cell and then numbering 1 thru n (depending on what the user selects. The first column should be the same, a blank cell and then 1 thru n. Then the multiplication table should be in the rows/columns of the table. Picture this:
I can't get mine to start with a blank cell in the top left-hand corner, instead it has 1 in that cell and the table starts calculating with 2x2.
Servlet code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
[Code] ....
View Replies
View Related
Jul 3, 2014
I have a code that writes the text file uploaded in a server but I want to write a text that I get it from jsp page by request, how can I write it?
FileInputStream fileToDownload ;
private static final int BYTES_DOWNLOAD = 1024;
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException{
response.setContentType("text/plain");
String name = request.getParameter("n");
response.setHeader("Content-Disposition",
[Code] ....
View Replies
View Related
Sep 29, 2014
I have a controller that on the basis of commands (formaction and subaction) dispatch requests to different jsp pages. But somehow when I am debugging my application, I can find duplicate request coming to the controller, so one jsp page does load twice. I am not sure from where the duplicate request is generating.
View Replies
View Related
Dec 14, 2014
we have deployed application on web sphere server and using servlets and jsp only.
View Replies
View Related
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
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
May 6, 2014
i am trying to do a program captures keystroke and mouseclick from user in a textarea and insert the details intoa text file using java. Mainly such as delay between keys, no. of times backspace being pressed, alt tab press and copy paste mouse click.
View Replies
View Related
Mar 15, 2015
I am trying to run a simple program in which on clicking on the TextField will show some required text under the Text Field .Here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Awt
{
public static void main(String...s)
[Code] ....
I am expecting the on clicking anywhere inside the text field should show me the Text : "Mouse Clicked" . But i am getting this error:
Awt.java:77: error: cannot find symbol
tf.f.setText("Mouse Clicked");}
^
symbol: variable f
location: variable tf of type Awt
1 error
View Replies
View Related
Nov 23, 2014
The explanation is a bit lengthy because I just tried to explain everything in one shot.
Link to the question
java - Show a System Tray notification or Desktop notification from the web application
View Replies
View Related
Jan 14, 2015
I have a lot of records in excel around 2000 rows and it can be more so what I am looking for is that I need to show this records in the web for front end user. I want to feel the user that it is the same as excel but web based so he can filter rows , highlight rows or columns and export whatever filtered by him . I have one sample photo for that program ( called IPCS ) , I am using it now but I need to make same like that in JSP or anything using java I can do it.
View Replies
View Related
Mar 19, 2014
i have a page where username is displayed...i want to uodate my table based on the page value i. e username..how can this be done
String sql;
sql = "UPDATE test SET username=? WHERE password=?";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1, "jumbomail@com");
statement.setString(2, "password");
View Replies
View Related
Dec 5, 2014
I've got a banner that displays on the web page and users can close it out by clicking an "X" button in its corner. Once it's closed, we track for that session that it remains closed, so a cookie gets set. I'd like subsequent requests to the server to be aware of this cookie so that the banner code is just not included in subsequent responses. (Sidebar: earlier I was just detecting the cookie after page load and then hiding the banner but it creates a lag where the banner is visible then suddenly pops away, making for poor user experience.)
I expect that even though Javascript set the cookie it would then show up in HttpServletRequest.getCookies() call, but there's actually a lot of cookies visible in Chrome Developer Tools on the client of my page that don't show up in .getCookies(). Does the HttpServletResponse.addCookie need called at some point first for the cookie to be passed back and forth to server?
View Replies
View Related
Feb 13, 2015
I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"
View Replies
View Related
Jun 4, 2014
I started a text based game, but I am dissatisfied with the console that PrintF prints to. How can I set up a window and have text output to that window, and have my player type responses in the window?
View Replies
View Related
Oct 25, 2014
So, I've been working on creating a text-based game engine that would create games similar to Achaea. It's been working pretty well so far. I just finished creating a great mapping system, but now I've run into a problem. I have a mapping system, but actually creating a map would prove to be quite a lot of work. Each location that the player can be inside of has a name, description, map symbol, and an array of the things inside of it. How can I make some sort of map creation program or something so that I can create my maps more easily?
I thought perhaps making a constructor that accepts a list of files, the first containing a table of strings for the names, the second containing a table of strings for the descriptions, etc.; but it seems that would be quite tedious and may be more complex than actually just hard-programming maps.
View Replies
View Related
Dec 18, 2014
i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.
Java Code:
import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Player playerObject = new Player();
[code]....
My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?
I tried like 'int Mongoloid = 1; int Caucasian = 2;'
And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.
View Replies
View Related