📄 verifylogin.jsp
字号:
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<%
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 'verifylogin.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 strUserName = request.getParameter("txtUserName");
//获取提交的密码:
String strPassword = request.getParameter("txtPassword");
if((strUserName ==null)||(strUserName.equals(""))||(strUserName.length()>20)){
response.sendRedirect("login.html");
}
if((strPassword ==null)||(strPassword.equals(""))||(strPassword.length()>20)){
response.sendRedirect("login.html");
}
String url="jdbc:mysql://localhost:3306/bookstore";
Class.forName("com.mysql.jdbc.Driver");
String username="root";
String password="ptnest";
Connection con=DriverManager.getConnection(url,username,password);
Statement stmt=null;
ResultSet rs=null;
try{
String sql = "select * from admin where name='"
+ strUserName + "' and pass='" + strPassword + "'";
//创建数据记录集对象:
stmt = con.createStatement();
//执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
//如果记录集为非空,表明有相匹配的用户名和密码,登录成功:
if (rs.next()) {
//登录成功时,把strUserName设成session变量UserName
session.setAttribute("UserName",strUserName);
response.sendRedirect("index.jsp");
} else {
//否则(记录集为空),表明失败:
out.println("<div align=center><font color=#FF0000>登录失败!</font></div>");
out.println("");
out.print("<div align=center><font color=#FF0000><a href=/bookstore/admin/login.html>点击此处返回</a></font></div>");
}
stmt.close();
con.close();
}catch(SQLException ex){
System.err.println("SQLException: "+ ex.getMessage());
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -