You are on page 1of 3

8.

WEB APPLICATION USING SERVELET AND JDBC

<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

Sample login Example (try with username as "admin" and password as "admin" without quart
)<br><br>

<form action="LoginController" method="post">

Enter username :<input type="text" name="username"><br>

Enter password :<input type="password" name="password"><br>

<input type="submit" value="Login">

</form>

</body>

</html>

PACKAGE:

packagecom.candidjava;

importjava.io.IOException;

importjavax.servlet.ServletException;

importjavax.servlet.http.HttpServlet;

importjavax.servlet.http.HttpServletRequest;

importjavax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class LoginController

*/

public class LoginController extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

String un=request.getParameter("username");

String pw=request.getParameter("password");

if(un.equals("admin") &&pw.equals("admin"))

response.sendRedirect("success.html");

return;

else

response.sendRedirect("error.html");

return;

}
<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

Login success

</body>

</html>

<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

Invalid username or password

</body>

</html>

You might also like