Losing session attribute

Hi ,

I have a servlet acting as a front controller which uses a JSP via request.getRequestDispatcher(main.jsp) to handle the display.

The JSP uses a servlet to handle the display of some hyperlinks.

I set an attribute in the controller servlet to true but in the servlet displaying links remains null. I have checked the contextPath and the session ID but they are the same.

=========== Controller ==============

ContextPath: /FrontController

session ID : f360d85b5e8fe7e5bbafac03cd69

Session attribute: true

=========== Processing Links Tag ==============

ContextPath: /FrontController

session ID : f360d85b5e8fe7e5bbafac03cd69

Session attribute: null

Does anyone have any ideas what I'm doing wrong?

thanks in advance,

J

[814 byte] By [dr.jgha] at [2007-11-27 11:25:23]
# 1

You have double checked the spelling of the attribute name to ensure that it is correct and properly capitalized in all places?

tolmanka at 2007-7-29 16:04:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thank you tolmank,

I had "logged_on" everywhere except in the controller which was "logged_in"

J

dr.jgha at 2007-7-29 16:04:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Use a constant which can be definied in *one* place.

public final class Constants {

public static final String SESSION_KEY_LOGGED_IN = "logged_in";

}

public class SomeServlet extends HttpServlet {

doGet(req, res) {

Boolean loggedIn = (Boolean) req.getSession().getAttribute(Constants.SESSION_KEY_LOGGED_IN);

}

}

If Java >= 1.5, then you can also use enum instead of a final class with static constants.

BalusCa at 2007-7-29 16:04:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...