0

I have a custom attribute defined in a HttpSession and I set the attribute from within a library class as follows:

public class changeBeanAttribute {
public changeBeanAttribute() 
{
}
public void changeAttribute (HttpServletRequest request) {
       request.getSession().setAttribute("CustomAttribute","Sample Attribute Value");
}
}

However, when I attempt to access the modified attribute from a JSP page as follows, I get a null value returned

<% String str = request.getSession().getAttribute("CustomAttribute"); %>

Can someone help me understand why I can't access the HttpSession attribute from the JSP page?
Both the the JSP page and Java class are running in a Tomcat container.

informatik01
  • 16,038
  • 10
  • 74
  • 104
  • 1
    It's hard to say. Either the session has timed out, or the changeAttribute() method has not been called, or the second request in made from another session, or another request has reset this attribute to null or removed it from the session. – JB Nizet Feb 04 '13 at 09:47
  • As a side note: [Using scriplets in JSP is highly discouraged](http://stackoverflow.com/a/3180202/814702) – informatik01 Feb 04 '13 at 16:16

1 Answers1

0

Have you tried setting

<%@ page session="true"%>

on top of your jsp page? I think it's default, but maybe you've set it to false. It allows your session to be available on your jsp page.

javacoder
  • 732
  • 1
  • 12
  • 24