您好,登錄后才能下訂單哦!
登錄界面:
find.jsp:
<%@page contentType="text/html" import ="java.sql.*" pageEncoding="UTF-8"%>
<html>
<head><title>登錄</title></head>
<body>
<%
request.setCharacterEncoding("utf-8");
String id=request.getParameter("id");
String passwd=request.getParameter("passwd");
boolean flag=false;
PreparedStatement sql=null;
ResultSet rs=null;
Connection conn=null;
%>
<%
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String userPwd = "aaa312";
String dbName="students";
String url1 = "jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=utf-8";
String url=url1+url2+url3;
Class.forName(driverName);//加載驅(qū)動(dòng)
conn= DriverManager.getConnection(url,userName,userPwd);
sql =conn.prepareStatement("select * from students_info where id=? and passwd=?");
sql.setString(1,id);
sql.setString(2,passwd);
rs=sql.executeQuery();
if (rs.next()) {
flag=true;
}
rs.close();
sql.close();
conn.close();
%>
<!-- 判斷是否是正確的登錄用戶 -->
<% if(flag==true)
{%>
<jsp:forward page="s.jsp"/>
<% }else response.sendRedirect("f.jsp");%>
</body>
</html>
s.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'welcome.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%String Name=request.getParameter("username");%>
歡迎你,<%=Name%>成功登錄!
</body>
</html>
f.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
對(duì)不起,你的信息有誤,請(qǐng)重新登錄! <br/>
<form action="login.jsp" method="post">
<input type="submit" value="返回登錄"/>
</form>
</body>
</html>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。