Java Exp7
Java Exp7
Java Exp7
Code
Index.jsp
<% @page contentType = "text/html" pageEncoding = "UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title> Form validation </title>
<meta charset = "UTF-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<style>
Input {
margin: 10px;
}
Body {
background-color:#2c74c7;
text-align:center;
}
</style>
</head>
<body>
<div>Form Validation using JSP</div>
<form action = "login.jsp" method="POST">
<label> Enter your Username: </label>
<input type = "text" name = "uname">
<br>
<label>Enter your Password: </label>
<input type = "password" name = "pswd">
<br>
<input type = "submit">
</form>
</body>
</html>
Login.jsp
<%
String username = request.getParameter(" uname ");
String password = request.getParameter(" pswd ");
if(username.equals(" admin ") && password.equals(" admin") ) {
out.println(" You are logged in!! ");
} else {
out.println(" Try Again!! Wrong Credentials ");
}
%>
Output: