<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String userName=request.getParameter("userName");
String pwd=request.getParameter("pwd");
//加载数据库驱动
Class.forName("com.mysql.jdbc.Driver");
//连接数据库
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/goodmanager","root","");
//对数据库语句预编译
String sql="select * from user where username=? and password=?";
//为预编译赋值
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,userName);
ps.setString(2,pwd);
ResultSet rs=ps.executeQuery();
if(rs==null){
response.sendRedirect("login.jsp");
}else{
response.sendRedirect("main.jsp");
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action ="login.jsp" method="post">
<table>
<tr>
<td>用户名:<input type="text" name="userName"/></td>
</tr>
<tr>
<td>密码:<input type="password" name="pwd"/></td>
</tr>
<tr>
<td colspan="2">
<input style="border:0" type="text" id="erromessage">
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交"/> </td>
</tr>
</table>
</form>
</body>
</html>