You are on page 1of 3

Lab5.

jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Page</title>
</head>
<body>
<h1>Session Tracking</h1>
<form method="post" action="Lab5a">
<label>User Name:</label><input type="text" name="name">
<label>Password :</label><input type="password" name="pass">
<input type="submit">
<!--<a href="Lab5a"></a>-->
</form>
</body>
</html>

Lab5a.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Lab5a extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)throws
IOException, ServletException
{
try
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

String n=req.getParameter("name");
String p=req.getParameter("pass");
out.print("Welcome"+n);

HttpSession session=req.getSession();
session.setAttribute("uname",n);
session.setAttribute("upass",p);

out.print("<br><a href =\"LAB5b\">Click here to know your


password</a>");

out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Lab5b.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class LAB5b extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws
IOException, ServletException
{
try
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();

HttpSession session=req.getSession(false);
String n1=(String)session.getAttribute("uname");
String p1=(String)session.getAttribute("upass");

out.print("Hello" +n1+ "your password is" +p1);


out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Lab6(index.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Include</title>
</head>
<body>
<h1>Hello!</h1>
<jsp:include page="include.jsp" />
</body>
</html>

Lab6(include.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Include JSP Page</title>
</head>
<body>
<h1>YOU ARE IN ADVANCED JAVA LAB</h1>

</body>
</html>

lab6(inc.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Executing forward attribute</h1>
<jsp:forward page="forward.jsp" />
</body>
</html>

lab6(forward.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Forward JSP Page</title>
</head>
<body>
<h1>This is JSP Forward Page </h1>
</body>
</html>

You might also like