packageservlets;importjava.io.IOException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;im...
package servlets;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String user=req.getParameter("user");
RequestDispatcher rd=null;
if(user!=null&&user.equals("admin")){
req.getSession().setAttribute("login", "true");
rd=req.getRequestDispatcher("/admin.html");
rd.forward(req, resp);}
else if(user!=null&&user.equals("common")){
req.getSession().setAttribute("login", "true");
rd=req.getRequestDispatcher("/common.html");
rd.forward(req, resp);
}
else{
resp.sendRedirect("/ch08/login.html");
}
}
}
web的配置
LoginServlet
servlets.LoginServlet
LoginServlet
/servlet/LoginServlet
LoginValidationFilter
servlets.LoginValidationFilter
login.html
选择用户 | |
管理员 普通用户 |
展开