Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

shopping problem in servlet  RSS feed

 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...i am going to make a servlet. the servlet will get parameter from a html page. say the user is entering shopping1,shopping2 in 2 text boxes and then pressed submit button.

now the servlet should show the list entered by the user and then ask for a confirmation whether he want to confirm "add to database " or canceal.

i am in problem to do the last part. how do i write code to confirm the things user have chosen ?



after pressing submit i would like to get an page which will show all the shopping user have chosen and then ask for a confirmation.



do i need to use Httpsession ? what feature of servlet will be useful for this kind of problem ?
 
Kunaal A Trehan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Create a session and maintain an arraylist holding the shopping details
Put that arraylist in the HttpSession.

And use that.
I hope it helps

Rgds
Kunal
 
salvador rcn
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the response.

ok i am using arraylist. i am stoing data in the arralist.

here are pseudocode.

String data1 = req.getParameter("some_data");
String data2 = req.getParameter("some_another_data");

arrayListObject.add(data1);
arrayListObject.add(data2);


for(int k=0;k<arrayListObject.size();k++) out.println( (String)arrayListObject.get(k) ));



But problem is as soon as I AM USING BACK BUTTON OF the IE and going back to add more elemnts through my .html page . it is not adding to the arrayList and not diaplaying all the things. Only the last two things are displyed.


i want user would add some data . then it would be displayed . if he goes back and add some more data then all those will also be displayed . there would be option ADD/CANCEAL to the database for all these data entered.


But ArrayList is forgetting those old values as soon as i am going back to add some more data in .html page.

can you tell how do i solve the above problem.
 
Huiyang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,here are some code ,I wish you can gain some from them.

session = request.getSession();
if(session.getAttribute("shopping")==null){
Collection shoppings = new ArrayList();
session.setAttribute("shopping",shoppings);
}
Collection shoppings =session.getAttribute("shopping");
shoppings.add(req.getParameter("some_data"));
shoppings.add(req.getParameter("some_another_data"));
session.setAttribute("shopping",shoppings);
[ June 25, 2004: Message edited by: Huiyang ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!