• Post Reply Bookmark Topic Watch Topic
  • New Topic

updating session value in servlet but the same session in jsp page is not updated

 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all..
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..
and solution for that??
or any other good method to do the same?? please help
 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try AJAX to update the purchase amount in your JSP page.
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, via ajax.. i will work..
but it is not look like a good work, to refresh the page after every say n seconds..??
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think updating the page should be necessary.

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,

What does this onclick handler do? Obviously it must access some servlet to do this checking...?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this onclick handler, sends the hidden parameters like totalpurchase and minimumorder (amount) to javascript, which checks that totalpurchase must not be smaller than minimumorder to proceed to final checkout..
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, since you said "my jsp page is unable to rechognise the updated value of the totalpurchase", it sounds as if there is a bug in the JavaScript code?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jsp file



servlet file



yes, its unable to rechognise the updated value of the totalpurchase , since it only rechognise the updated value, after a page refresh..

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think I understand the flow. The hidden value obviously can only reflect what was put into the cart before the current page was displayed - you'd need to update that with whatever was added to the cart on the current page. Is that the problem? Or are you saying that the hidden field does not have the correct value to begin with?
 
shivam singhal
Ranch Hand
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks for trying to understand..

actually i have a jsp file contains cart (as a div tag) and many other div tags in which the item to be added in the cart are placed.., now when user clicks on the item , in the backend the control will go to the servlet in which session is created and synchronized then the control moves to other servlet which adds the item in the arraylist (Backend - cart ) and show those items in the jsp page's div tag(UI - cart) and also set a session variable,value (totalpurchase) ,

UI (JSP file)
now after this, when user saw the item is added in the cart, he wants to proceed to final checkout, when user clicks on the final checkout button(after that div tag in the JSP page), i want the ( updated ) value of that session variable ( totalpurchase ) ,

Error: totalpurchase value is "0" , that is, it is not changed according to the new value updated by the servlet.
and yes, if i refresh my page at this stage, then it catches the correct value..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!