session expire(not exist)

hi,

here is my code:

public void doGet (HttpServletRequest _req, HttpServletResponse _res)

throws ServletException, IOException {

/* Refresh session attributes */

session = _req.getSession();

session.removeAttribute("loginError");

session.removeAttribute("submitError");

String action_get = _req.getParameter("action_get");

String rachunek = _req.getParameter("rachunek");

String bc = _req.getParameter("bc");

// log off user

if (action_get.equals("logout")) {

loginError_logout(_req, _res);

}

else if (action_get.equals("showReport")) {

/* Make sure the user has logged in before recording the data */

String validUser = (String) session.getAttribute("validUser");

if (validUser.equals("y")) {

gotoPage("showReport.jsp", _req, _res);

} else { /* If the user did not login, then send them to the login page */

loginError(_req, _res);

}

}

I have problem: at JSP/servlet page i have a few links, after about 30 minutes without any action the session not exist, and when user click at some link then have error: (HTTP Status 500-The server encountered an internal error () that prevented it from fulfilling this request.): java.lang.NullPointerException at line:

if (validUser.equals("y")) {

i try to put this above the error line:

if (session == null) {

gotoPage("index.jsp", _req, _res);

}

but this is still problem

thanks if anyone can help

[1533 byte] By [pvwa] at [2007-11-27 11:23:50]
# 1

1) Move the "validUser" logic to a Filter.

2) If you want to redirect to index page when a session times out (bad design, but it's your choice), then add the following to the HTML head:<meta http-equiv="refresh" content="<%= session.getMaxInactiveInterval() %>;url=index.jsp">

BalusCa at 2007-7-29 15:54:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

i only replaced my error line with:

if (validUser != null && validUser.equals("y")) {

and it's working now

thanks

pvwa at 2007-7-29 15:54:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...