Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

shopping problem in servlet

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic