1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

JSP Tutorials

Session Example in JSP

track the session between different JSP pages:

page1.jsp
-------------------------------------------------
<%@ page language="java" %>
<html>
<head>
<title>page1</title>
</head>
<body>
<form method="post" action="savesession.jsp">
Name: </b><input type="text" name="name" value=""><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

The above code of the JSP page1.jsp that takes the input from user.


savesession.jsp
-------------------------------------------------

<%@ page language="java" %>
<%
String name=request.getParameter("name");
session.setAttribute("name",name);
%>

<html>
<head>
<title>Name Saved</title>
</head>
<body>
<p><a href="showsession.jsp">Next Page to view the session value</a><p>
</body>
</html>

The savesession.jsp save the name into session.

showsession.jsp
-------------------------------------------------
<%@ page language="java" %>
<%
String name=(String) session.getAttribute("name");
%>
<html>
<head>
<title>Show value</title>
</head>
<body>
Name is: <%=username%><p>

</body>
</html>

Now in the broswer if you do
http://localhost:8080/page1.jsp

then enter name and submit.

you can get the same value in showsession.jsp.

The function session.getAttribute("name") is used to retrieve the name saved in the session.

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy