Session check

Hi Experts,

What I need is to find out if the JSP page opened first time within session or may be there is another way but without using URL string.

Thank you.
LVL 1
fpoyavoAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
JNicConnect With a Mentor Commented:
Hi,

there are of course many ways you can do this.

Here is one way:

When your action-class has determined that the user has opened the page, you set a parameter:

HttpSession session=request.getSession();
session.setAttribute("didUserOpenPage1", "yes");

In the jsp:

<%
HttpSession session=request.getSession();
String didUserOpenPage1=session.getAttribute("didUserOpenPage1");
if(didUserOpenPage1.equals("yes"){
  System.out.println("OH NO! HE HAS OPENED THIS PAGE BEFORE!!!!!");

}
// here you know its the 1. time
%>
0
 
fpoyavoAuthor Commented:
:) Cool I will check this out.
0
 
fpoyavoAuthor Commented:
Thank you.
0
 
JNicCommented:
My pleasure! Thanks for accepting! :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.