• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to remove an object from session in a jsp?

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Can someone help me how to remove a session object every time when the user is navigated to a jsp page. I have these lines of code but it's not working.

user.jsp


The reason for doing this is when ever i come to this user.jsp from account.jsp with a different account number this user.jsp is not refreshed and i still see the same old userers for the previous account that i naviated before. Also please let me know if there is any other approach to acheive this task

Thank you very much in advance
 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi vishnu bola..

How about if you use scriptlet in JSP to remove the object from session?..
you could try to run this code :


Hope that helps..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leonardo Carreira wrote:How about if you use scriptlet in JSP to remove the object from session?


What terrible advice! He's already using modern JSTL to perform the action, and you adivise him to regress to 2002-style code with scriptlets?

Let's figure out how to fix the problem, not resort to antiquated and discredited methods to apply band-aids!
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear Bibeault for your "hot" correcttion..
i really appreciate it..

he asked about other approach to remove object from session..
so, i told him to use scriptlet.. //perhaps this is wrong suggestion
yes, i'm so sorry if i'm mistaken..

Thanks in advance sir..
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not a good suggestion. Not only are scriptlets to be avoided in modern JSP pages, any problems (aside from a mis-configured web app that prevents the JSTL from running) that is preventing his JSTL solution from working will also prevent any scriptlet solution from working.
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay.. Thanks Bear..
 
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vishnu bola wrote:Hi

Can someone help me how to remove a session object every time when the user is navigated to a jsp page. I have these lines of code but it's not working.

The reason for doing this is when ever i come to this user.jsp from account.jsp with a different account number this user.jsp is not refreshed and i still see the same old userers for the previous account that i naviated before. Also please let me know if there is any other approach to acheive this task

Thank you very much in advance


===


A better approach would be to have a controlled servlet add/remove session objects. JSP -> to JSP design is not recommended. Stick a controller or controlled servlet in the middle of those two JSP's.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I tried this piece of code and it works for me. When you use <jsp:useBean> it will create a new instance of the bean if not found in the mentioned scope. May be the instance variables of your bean are initialized by default. The new bean instance will have default values.
 
vishnu bola
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Thanks for all your responses.

Leonardo - The scriplet doesn't seem to work either.not sure of the reason though.

Charles - i like your idea of having a controlled servlet but not sure how to acheive it. can you please eloborate.

vaib- can you please let me know how to check if the instance variables of the bean are initialized by default?

Regards
vishnu

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vishnu bola wrote:Leonardo - The scriplet doesn't seem to work either.not sure of the reason though.


I already said that this is what would happen. If the JSTL doesn't work, the scriptlet doing the same thing won't work either.
 
Charles 'King
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vishnu bola wrote:
Charles - i like your idea of having a controlled servlet but not sure how to acheive it. can you please eloborate.



Instead of having account.jsp call user.jsp, it should call your controlled servlet or controller. Your controlled servlet would be responsible for add/removing session and other scoped variables; then forward your request to user.jsp.

Processing order: account.jsp -> controlled servlet -> user.jsp.

Remove this out of your JSP: <c:remove var="manageuserscontroller" scope="session" ...

Put the code for removing the session var into your servlet...

 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic