Creating a login page using servlet -
Concepts of Dispatcher
First you need to create a html page
<html>
<head>
<title></title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
</head>
<body>
username:<input type="text" name="username"><br>
Password:<input type="text" name="password"><br>
<input type="submit" value="submit">
</body>
</html>
Now create servlet
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "dispatcherservlet", urlPatterns = {"/dispatcherservlet"})
public class dispatcherservlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String ab=request.getParameter("username");
String bc=request.getParameter("password");
out.println(ab);
out.println(bc);
if(ab.equals("root")&& bc.equals("om"))
{
out.println("successful login");
}
else
{
out.println("loging failure");
RequestDispatcher rd=request.getRequestDispatcher("path of any file");
rd.forward(request, response);
}
} finally {
out.close();
}
}
7 Jun 2013
How to create a login page for any website
Login Page in Html
<html>
<head>
<title></title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
</head>
<body>
username:<input type="text" name="username"><br>
Password:<input type="text" name="password"><br>
<input type="submit" value="submit">
</body>
</html>
Output:
Username:
<html>
<head>
<title></title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
</head>
<body>
username:<input type="text" name="username"><br>
Password:<input type="text" name="password"><br>
<input type="submit" value="submit">
</body>
</html>
Output:
Username:
Subscribe to:
Posts (Atom)