This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp: hidden field problem  RSS feed

 
shaz akhtar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

ive got a little problem with jsp hidden fields, i am using them to pass values from one jsp page to another for my shopping cart project. I have got a main page which lists all the products and each product has an idnumber..when the user clicks "buy" it takes the user to a page which checks if the item allready exists in cart..if it does then it redirects the user to another page. it works till here! the problem is if the item does not exist in the cart..it inserts the values into a tempcart table.

How do i get the idnumber from the 1st page (the list of products) to this insert page? Currently ive got

<input type="hidden" name="dvddownload" value="<%=idnumber%>"> on each page at the bottom. but i get an error message:

cannot resolve symbol
symbol : variable idnumber
location: class org.apache.jsp.idexists_jsp
out.print(idnumber);

If i leave the value blank then it obviously inserts null as idnumber into my tempcart table.

i would really appreciate if anyone can help me this!!!
Thanks Shaz!!
[ January 04, 2005: Message edited by: Bear Bibeault ]
 
Vijaypal Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shaz,

I'am not sure whether this is the best possible solution but can you try putting the value in Session Scope...
 
shaz akhtar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry but im fairly new to jsp, how would i define a session scope and include the idnumber across the multiple pages?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set your idNumber in the session like this.

session.setAttribute("idNumber",idNumber);

and retrieve it using,

session.getAttribute("idNumber");
 
shaz akhtar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried using session scope. In my first page which is (list.jsp) i have done:

String stridnumber = request.getParameter("dvddownload");
session.setAttribute("IdNumber", stridnumber);

the parameter dvddownload has the value <%idnumber%> which i want to hold in the session scope. This is then passed to ifexists.jsp page which checks if the item exists..then passed through the 3rd page which is insert.jsp..in that page i have used the following to get the attribute

String strdvddownload = session.getAttribute("IdNumber");
i use the string strdvddownload to insert the idnumber which should be stored in the session to the temp cart table.. the select stmnt is as following:
"insert into tempcart values('"+strsessionid+"', '"+strdvddownload+"')";

It inserts the sessionid but im getting NULL for idnumber???
also when compiling get the following error message:

incompatible types
found : java.lang.Object
required: java.lang.String
String strdvddownload = session.getAttribute("IdNumber");

what am i doing wrong here? pls pls pls plss help!

thanks shaz
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String strdvddownload = session.getAttribute("IdNumber");


Typecasting is needed pal.

String strdvddownload = (String)session.getAttribute("IdNumber");

Tip: You had better read the docs first.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!