Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm working on struts1.3.8. The JSP page contains scriptlet to iterate the data in the session. Once the user opens the page and not performing any operation till the session expires and then next refreshing it is throwing java.lang.NullPointerException.

So how to handle that exception and how to make the session alive?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
202 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can rely on the existence of a well-known attribute in session.

Set this when the session is first created.

session.setAttribute("well-known-attribute", "abcd");

In your JSP, check if this attribute exists before you do any iterations.

if(session.getAttribute("well-known-attribute") != null) {
    // iterate others now
} else {
    session.setAttribute("well-known-attribute", "abcd");
    // now add the other attributes.
}

A new session will always be created if

  • There isn't one already AND
  • There is a request associated.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...