Adv Java - [Java Server Page: Session Management]

♠ Posted by Unknown in at 08:52

Java Server Page Session Management

The HTTP is stateless protocol. The state management is a necessary management technique to preserve current page data from moving one page to another page. The Session management is one type of state management to maintain particular user login/logout session tracking. The Session is created individually for every particular user who are getting logged in/out on website.

<%--  Write a JSP program to implement the concept of session tracking --%>
<%-- Getting and setting sesion object values --%>
<HTML>
<BODY>
                        <H1>Session Id : <%= session.getId() %>  </H1>
                        <H3>
                           <LI> This session was created at <%= session.getCreationTime() %> </LI>
                           <LI>Old MaxInactiveInterval = <%= session.getMaxInactiveInterval() %> </LI>
                           <% session.setMaxInactiveInterval(5); %>
                           <LI> New MaxInactiveInterval = <%= session.getMaxInactiveInterval() %> </LI>
                         </H3>

                         <H2>If the session object "My dog is still around,  this value will be non-null: </H2>
                         <H3><LI>Session value for "My Dog"  =  <%= session.getAttribute("My dog") %> <LI> </H3>
                         <% session.setAttribute("My dog", new String("Ralph")); %>

                         <H1>My Dog's name is <%= session.getAttribute("My dog") %> </h1>

                         <FORM TYPE = "POST" ACTION = "SessionObject2.jsp">
                         <INPUT TYPE = "submit" NAME = +"Submit" VALUE = "Invalidate">
                         </FORM>

                         <FORM TYPE = "POST" ACTION = "SessionObject3.jsp">
                         <INPUT TYPE = "submit" NAME = +"Submit" VALUE = "Keep Around">
                         </FORM>
</BODY>
</HTML>


//SessionObject2.jsp
<HTML>
<BODY>
<H1>Session Id : <%= session.getId() %> </H1>
<H1>Session value for "My Dog" <%= session.getValue("My Dog") %> </H1>
<% session.invalidate(); %>
</BODY>
</HTML>

//SessionObject3.jsp
<HTML>
<BODY>
<H1>Session Id : <%= session.getId() %> </H1>
<H1>Session value for "My dog"  <%= session.getValue("My dog") %></H1>
<FORM TYPE = "POST" ACTION = "Practical32.jsp">
<INPUT TYPE = "Submit" NAME = "Submit" VALUE = "Return">
</FORM>
</BODY>
</HTML>


2 comments:

Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here!
Good luck for the next post buddy..
Staffing Companies in Bangalore
HR franchise in Bangalore

The blog gave me idea about components of selenium. They explained in effective manner. Thanks for sharing it. Keep sharing more blogs.

Selenium Training in Chennai

Post a Comment