这是处理post 的方法
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
String username=request.getParameter("username");
String password=request.getParameter("password");
LoginJavabean aa = new LoginJavabean();//业务处理Bean的对象
String temp=aa.login(username,password);
HttpSession session = request.getSession();
if(temp.equals("1")){
session.setAttribute("user1", username);
response.sendRedirect("main.jsp");
}
else if(temp.equals("2")){
session.setAttribute("user1", username);
response.sendRedirect("main1.jsp");
}
else if(temp.equals("3")){
session.setAttribute("user1", username);
response.sendRedirect("main2.jsp");
}
else{
out.println("<script>");
out.println("alert('对不起,用户名或密码错误!');");
out.println("window.location='login.jsp'");
out.println("</script>");
}
}
/**
* Initialization of the servlet. <br>
*
*
@throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}