Open zhamri opened 7 years ago
Index :
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<h1 align="center"> LOGIN FORM </h1>
<form METHOD=GET ACTION="login.jsp">
Username : <input type="text" name="uname">
Password : <input type="password" name="passwd">
<input type="submit" value="LOGIN">
</form>
</body>
</html>`
Login
<!DOCTYPE html>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.*,javax.servlet.http.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body>
<sql:setDataSource
var="usr"
url="jdbc:mysql://localhost:3306/login"
driver="com.mysql.jdbc.Driver"
user="root" password=""
/>
<sql:query dataSource="${usr}" var="result1" >
select * from login where name=?
<sql:param value="${param.name}"/>
</sql:query>
<c:forEach var="row1" items="${result1.rows}">
<c:set var="flag1" scope="application" value="1"/>
</c:forEach>
<sql:query dataSource="${usr}" var="result2" >
select * from login where name=? and password=?
<sql:param value="${param.uname}"/>
<sql:param value="${param.passwd}"/>
</sql:query>
<c:forEach var="row2" items="${result2.rows}">
<c:set var="flag2" scope="application" value="1"/>
</c:forEach>
<c:choose>
<c:when test="${flag2 eq 1}">
<c:forEach var="row2" items="${result2.rows}">
<c:set var="flag2" scope="application" value="1"/>
<h1>
Correct <c:out value="${row2.uname}"/>
</c:forEach>
<c:set var="flag1" scope="application" value="0"/>
<c:set var="flag2" scope="application" value="0"/>
</c:when>
<c:when test="${flag1 eq 0}">
<h1>
User Not Registered
</h1>
<c:set var="user_flag" scope="application" value="0"/>
<c:set var="flag" scope="application" value="0"/>
</c:when>
<c:otherwise>
<h1>
Invalid Password , Try Again !!!
</h1>
<c:set var="user_flag" scope="application" value="0"/>
<c:set var="flag" scope="application" value="0"/>
</c:otherwise>
</c:choose>
<jsp:forward page = "helloworld.jsp" />
</body>
</html>
Hello World
<%@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>
<font size="10" color="red"><%="Hello World" %></font>
<br>
<font size="20" color="blue"><%="STIW2024 Software Engineering" %></font>
<body bgcolor="pink">
</body>
</html>
Reference. https://www.youtube.com/watch?v=MKVOiYLCzA8
index <%@ page import="java.sql.*" %>
login <%@ page import="java.sql.*" %>
Error In Login
HelloWorld
output
reference: https://www.youtube.com/watch?v=CeGDp0Rym5g
reference: https://www.youtube.com/watch?v=MKVOiYLCzA8
1st --> index.html 2nd --> loginto.jsp 3rd --> helloworld.jsp With correct password with Wrong password
Login.jsp Verify.jsp HelloWorld.jsp login database (MYSQL) Output Reference: http://www.lionblogger.com/simple-jsp-login-page-with-mysql/
Reference : https://www.youtube.com/watch?v=MKVOiYLCzA8
Reference: https://www.youtube.com/watch?v=MKVOiYLCzA8
REFERENCE : https://www.youtube.com/watch?v=MKVOiYLCzA8
<%--
Document : login
Created on : 2017-11-28, 3:07:31
Author : Aman
--%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet'>
<link href="./css/Loginbox.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<body>
<div class="text-center" style="padding:12% 0">
<div class="logo">Login</div>
<div class="login-form-1">
<form id="login-form" class="text-left">
<div class="login-form-main-message"></div>
<div class="main-login-form">
<div class="login-group">
<div class="form-group">
<label for="lg_username" class="sr-only">Username</label>
<input type="text" class="form-control input-lg" id="lg_username" name="lg_username" placeholder="username">
</div>
<div class="form-group">
<label for="lg_password" class="sr-only">Password</label>
<input type="password" class="form-control input-lg" id="lg_password" name="lg_password" placeholder="password">
</div>
<div class="form-group login-group-checkbox">
<input type="checkbox" id="lg_remember" name="lg_remember">
<label for="lg_remember">remember</label>
</div>
</div>
<button type="submit" id="check" class="login-button"><i class="fa fa-chevron-right"></i></button>
</div>
</form>
</div>
</div>
<%
try{
String username = request.getParameter("lg_username");
String password = request.getParameter("lg_password");
Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/SoftwareEngineering","root","****" );
PreparedStatement pst = conn.prepareStatement("Select Username,Password from login where Username=? and Password=?");
pst.setString(1, username);
pst.setString(2, password);
ResultSet rs = pst.executeQuery();
if(rs.next()){
%>
<jsp:forward page="index.jsp"/>
<%
}
}
catch(Exception e){
}
%>
<script src="./js/Loginbox.js" type="text/javascript"></script>
</body>
</html>
All students must create a new branch using "metric number" in your team repo.
Create a login page (
login.jsp
). If theuser_name
andpassword
are correct, then displayHelloWorld.jsp
(Issue #1 )Then upload
login.jsp
andHelloWorld.jsp
to the new branch.