• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

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

 
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try AJAX to update the purchase amount in your JSP page.
 
shivam singhal
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..??
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
were you ever able to get solution. I have encountered the same situation. Cart value is reduced in a servlet. But when returned back  to JSP page from servlet , the new value is not shown....

If I refresh the JSP page or go to another page, then the new value is updated.

Thank you
 
Sri Band
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind... I set the correct value in the request.getSession().setAttribute(xxxx) and the updated value is shown on return to JSP page
 
Marshal
Posts: 4915
624
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch  
 
We noticed he had no friends. So we gave him this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic