• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove an object from session in a jsp?  RSS feed

 
vishnu bola
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
  • 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
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • 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..
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 Java Postgres Database
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay.. Thanks Bear..
 
Charles 'King
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Vaib Gupta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!