Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

How to handle the Exceptions in JSP, when session expires?

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

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

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...