📄 userloginservlet.java
字号:
package mypack;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletException;
import mypack.*;
import java.io.IOException;
public class UserLoginServlet extends HttpServlet {
public void init() throws ServletException {
super.init();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
check(request, response);
}
catch(Exception e){
}
}
private void check(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
HttpSession session = request.getSession();
try{
Cdstore cdstore=new Cdstore();
session.removeAttribute("username");
String nextpage="";
//检查用户的密码
if(cdstore.verifyAdmin(username,password))
{
nextpage="/admin.jsp";
}
else if (cdstore.verifyUser(username, password))
{
session.setAttribute("username",username);
nextpage="/catalog.jsp";
}
else
nextpage="/login_failed.jsp";
this.getServletContext().getRequestDispatcher(nextpage).forward(request, response);
}
catch(Exception e){
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -