Question

I'm using a HttpSession session variable to store error/succes messages for various actions that my servlets are doing and I display those messages in jsp's when it requires.

But is it ok to create a new HttpSession object in each of the methods I use? Or should I create just a static one and hold there all my attributes? Thank you.

No correct solution

OTHER TIPS

If the purpose of that variable is only for success or error message, i would use request.setAttribute().

session.setAttribute() will keep that value through out the entire session, where as request.setAttribute() will keep that value available up to the life cycle of that request object.

You should not instantiate HttpSession yourself. To obtain HttpSession, use either HttpServletRequest#getSession() or HttpServletRequest#getSession(boolean). In JSP, you can use the session object directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top