• 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

Session.removeAttribute doesnt work

 
Ugly Redneck
Posts: 1006
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm using Websphere 5.0 Studio and I have a couple of attributes in my session object. At one point of time I remove some of them by using
request.getSession().removeAttribute("myAttribute")
However the values is still available elsewhere in the application. Any help on this?
Thanks
SR
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't think of any reason why that would fail to work - I suggest:
1. break that statement up into separate steps
get the session
use isNew() and getAttribute() to see if the session is not new and if it does indeed have the attribute you expect.
2. use getId() in both places to see if both are using the same session.
Bill
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
okie, if i face such a problem which in the past i have, on tomcat, i had a problem with set and get Attribute methods, now here u have a problem with removeAttribute.
There r 2 work arounds.
1.Use putValue,getValue and removeValue methods of HttpSession, although deprecated they work well and serve our purpose.
2.Option number 2 and definatelt wud work if setAttribute is working in ur case is httpsession.setAttribute("XYZ",null), where XYZ would be the name of variable u wish to delete from ur HttpSession.
Man, prefer going by putValue,getValue and removeValue methods.
Tell me, whether u could crack it.If u have'nt i will think of some more new tricks.
 
Paul McKenna
Ugly Redneck
Posts: 1006
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
Here is my code:
Servlet Code
------------
HttpSession session = request.getSession(false);

if (null != session) {
System.out.println("Session id : newtradeaction : "+session.getId());
if (null != session.getAttribute("newTradeForm")) {
session.setAttribute("newTradeForm", null);
session.removeAttribute("newTradeForm");
}
}
JSP Code
--------
<jsp:useBean class="com.gec.ctb.form.NewTradeForm" id="newTradeForm" scope="session"></jsp:useBean>
<%
System.out.println(newTradeForm.getId());
%>
And the damn attribute property is still there. The 2 session ids are the same. Cant understand it.
I used debug mode in IBM Websphere Studio and saw that even though I use the removeAttribute method it doesnt actually remove the value but removes something called "next"
 
Rohit Ahuja
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HttpSession Object is different from bean instances variable.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Careful with the <jsp:useBean session=true> tag. If the bean doesn't exist in the session(if you removed it), it will create a new one when the page with the <jsp:useBean session=true> tag in it is served up.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I sure would look at the actual Java servlet code that JSP generates to see if it is doing what you think it should be doing. In Tomcat it is under the /work directory but I dunno where Websphere keeps it.
Bill
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
JSP useBean tag would create a new session if it does not exist already..So to check if the attribute persist in the session don;t use usebean tag.
use
<%@page session = true%>
try session.getAttribute("newTradeForm");
check if this is null.

Geeta
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic