> I am using Jrun 2.3 with IIS
> Is there a quick way to gracefully direct the user to the beginning of the
> app where they can start a new session when the old one has been
> invalidated?
> Currently when the session times out, the user gets the following:
>
>
> 500 Internal Server Error
> servletname:
> java.lang.NullPointerException
>
>
> Thanks in advance.
> Joe.
>
Hi Joe,

I am assuming you are using servlets here and am also going to give you the
whole spiel too, sorry.

Each servlet that uses a session object -must- do the following

Session session = request.getSession(true);

This either creates a new Session when the session id is stale OR creates a
new Session if there is no received session
id OR gives you the existing session for that id.

In all servlets other than your entry point servlet check the session to see
if it isNew() and if it is
do the following

response.sendRedirect(response.encodeRedirectUrl("http://www.your.com/servle
t/EntryServlet"));

before any output is sent to the client.

trying to grab a stale session object should not cause the above exception
to occur. If it does then JRun has a bug in it
(wouldn't be the first one but hey).

If that lot does not work then try opening JRun Administrator application,
select JSE, Service Config, Session Tracking panel and set the
session timeout value to 3600000 = 1 hour or higher. Times are in
milliseconds.

What I think may be happening to you is that the stale session object
contains information that is stored between requests.
The session timesout, they go to another servlet and suddenly all the
information that was in the old session has been lost causing
the null pointer exceptions.

You can be a little more subtle however if you store all information that is
relevant in cookies that expire immediately when the browser is
closed. Just check for session.isNew() and if it is and you are not in the
entry servlet then grab the cookies, stuff everything into the session
object and voila, nothing seems to have happened :)

This way you can even forget about the session object for clients that are
liable to stand idle for long periods of time.

If the information in the session object is much too large to be efficiently
stored in cookies then lengthening the time before a session is
made stale is your only viable option though.

Hope this helps

Andy Bailey

PS There are probably 1000's of solutions out there, all better than mine
but thats how I would do it.....

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to