copy paste the code below
newjsp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<form action="log" method="post">
Name :<input type="text" name="name"><br>
PASS :<input type="password" name="pass"><br>
<input type="submit" name="submit" value="submit">
</form>
</div>
</body>
</html>
NewServlet.java
// a pure processing servlet to authenticate the user
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import java.sql.*;
public class NewServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
{
try
{
// get data of form
String username = req.getParameter("name");
String password = req.getParameter("pass");
if (username.equals("student") && password.equals("student"))
{
res.sendRedirect("index.html");
}
else
res.sendRedirect("newjsp1.jsp");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
newjsp.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Login page</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
<form action="log" method="post">
Name :<input type="text" name="name"><br>
PASS :<input type="password" name="pass"><br>
<input type="submit" name="submit" value="submit">
</form>
</div>
</body>
</html>
NewServlet.java
// a pure processing servlet to authenticate the user
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import java.sql.*;
public class NewServlet extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
{
try
{
// get data of form
String username = req.getParameter("name");
String password = req.getParameter("pass");
if (username.equals("student") && password.equals("student"))
{
res.sendRedirect("index.html");
}
else
res.sendRedirect("newjsp1.jsp");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment