Micro Teaching_JSP
Micro Teaching_JSP
Name of the Faculty: Dr. Avinash Dwivedi Program Name: B.Tech (CSE)
PREREQUISITES, AIM AND LEARNING
OUTCOMES
Prerequisite of topic: Basic concepts of web programming.
Aim: This session is to provide an elementary understanding of session
management in Java Server Pages(JSP). Students will learn the
importance of user session management and its implementation in web
development.
Learning Outcomes:
By the end of this session, students should be able to:
Understand the concept of session management and its
importance in web development
Apply session management principle to complete a transaction
2
SESSION TRACKING
Advantage of Cookies
Simplest technique of maintaining the state.
Cookies are maintained at client side.
Disadvantage of Cookies
It will not work if cookie is disabled from the browser.
Only textual information can be set in Cookie object.
Note: Gmail uses cookie technique for login. If
you disable the cookie, gmail won't work.
COOKIES API
<html> <body>
<form action = "main.jsp" method = "GET">
First Name: <input type = "text" name = "first_name">
<br />
Last Name: <input type = "text" name = "last_name" />
<input type = "submit" value = "Submit" />
</form>
</body> </html>
MAIN.JSP
<%
// Create cookies for first and last names.
Cookie firstName = new Cookie("first_name",
request.getParameter("first_name"));
Cookie lastName = new Cookie("last_name",
request.getParameter("last_name"));
// Set expiry date after 24 Hrs for both the
cookies.
firstName.setMaxAge(60*60*24);
lastName.setMaxAge(60*60*24);
// Add both the cookies in the response
header.
response.addCookie( firstName );
response.addCookie( lastName ); %>
MAIN.JSP
<html> <head> <title>Setting Cookies</title> </head>
<body>
<center>
<h1>Setting Cookies</h1>
</center>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("first_name")%>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("last_name")%>
</p></li>
</ul>
<form action="navigate.jsp" method="post">
<label for="url">Enter URL:</label>
<input type="text" id="url" name="url">
<input type="submit" value="Go">
</form> </body> </html>
NAVIGATE .JSP