81,090
社区成员
发帖
与我相关
我的任务
分享
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession mySession = request.getSession(true);
mySession.setAttribute("errMsg", "");// 清空错误信息
String username = request.getParameter("username"); // 获取参数值
String password = request.getParameter("password");
String identfiy = request.getParameter("identfiy");// 获取参数传来的验证码
String sessionIdentiy = (String) mySession
.getAttribute("Login_Image_Code"); // 获取session里的验证码
String conformPswd = "";
String sql = "select * from user where username='" + username + "'";
if (identfiy == "" || identfiy.length() < 1) { // 验证码为能为空
mySession.setAttribute("errMsg", "验证码不能为空!");
response.sendRedirect("/loginuser/login.jsp");
} else if (!identfiy.toUpperCase().equals(sessionIdentiy.toUpperCase())) { // 验证验证码是是否一致
mySession.setAttribute("errMsg", "验证码错误!");
response.sendRedirect("/loginuser/login.jsp");
}
ResultSet rs = null;
mvconnection mvc = new mvconnection();
if (mvc != null) {
rs = mvc.getResultSet(sql);
} else {
return;
}
if (rs != null) {
try {
while (rs.next()) {
if (rs.getString(3) != null) {
conformPswd = rs.getString(3);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
}
} else {
mySession.setAttribute("errMsg", "用户名不存在!");
response.sendRedirect("/loginuser/login.jsp");
}
if (password.equals(conformPswd)) {
if (username.equals("guest")) {
sql = "select * from user where enroll= 0";
rs = mvc.getList(sql);
mySession.setAttribute("rs", rs);
response.sendRedirect("/loginuser/guest.jsp");
} else if (username.equals("admin")) {
sql = "select * from user where enroll= 1"; // 通过的
rs = mvc.getList(sql);
mySession.setAttribute("rs", rs);
RequestDispatcher requestDispathcer = request.getRequestDispatcher("/admin.jsp");
requestDispathcer.forward(request, response);
} else if (username.equals("user")) {
sql = "select * from user where enroll= 1"; // 通过的
rs = mvc.getList(sql);
// set attribute here
mySession.setAttribute("rs", rs);
response.sendRedirect("/loginuser/user.jsp");
}
} else {
return;
}
}
public ResultSet getList(String sql) {
ResultSet rs = null;
Statement stmt = null;
Connection con = null;
con = this.dbC.getConnection();
if (con != null) {
try {
stmt = con.createStatement();
if (stmt != null) {
rs = stmt.executeQuery(sql);
if (rs != null) {
return rs;
} else {
return null;
}
} else {
return null;
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
} else {
return null;
}
}
<%@ page language="java" pageEncoding="gb2312"%>
<%@ page import ="java.sql.*" %>
<%
ResultSet rs = null;
if(session.getAttribute("rs")!=null){
Object ob = session.getAttribute("rs");
rs = (ResultSet)ob;
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%
System.out.println(request.getRequestURL());
%>
<title>admin</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>
<table width="500" border = "2" align="center">
<tr> <th>id</th> <th>用户名</th> <th>简历信息</th> <th>审核情况</th> <th>是否录取</th><th>操作</th></tr>
<%
while(rs.next()){
%>
<tr><td><%=rs.getInt("id")%></td><td><%= rs.getString("username") %></td><td><%=rs.getString("info") %></td>
<td><%=rs.getString("enroll") %></td><td><%= rs.getString("verify") %></td><td><a href="/loginuser/update.jsp">修改</a> <a href="updateServlet?method=delete&id=<%=rs.getInt(1)%>">删除</a></td></tr>
<%} %>
</table>
</body>
</html>