public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html");
UserDao ud=new UserDao();
String username=request.getParameter("user");
String userpassword=request.getParameter("pwd");
boolean flag=ud.sel(username);
System.out.println(username);
System.out.println(userpassword);
System.out.println(flag);
PrintWriter out = response.getWriter();
if(flag){
out.print("The user name has been registered!");
}else{
out.print("<script>window.location.href='login.jsp';</script>");
//response.sendRedirect("login.jsp");
}
}
用out.print("<script>window.location.href='login.jsp';</script>");显示
用response.sendRedirect("login.jsp");这个显示
servlet?ajax?jsp
------解决方案--------------------
再客户端跳转,服务端跳转ajax不会理会的
// out.print("<script>window.location.href='login.jsp';</script>");
out.print("1");
if(ajaxobj.responseText=='1')window.location='login.jsp'