doPost解决乱码问题:
代码必须放在第一排。
request.setCharacterEncoding("utf-8");
doGet解决乱码问题:
每一个获得的属性都需要进行转码。
String username = request.getParameter(“username”);username = new String(username.getBytes(“iso-8859-1”),“UTF-8”);
请求转发和请求重定向:
if(username.equals("123")&&password.equals("123")){ request.getRequestDispatcher("/success.html").forward(request, response); }else{ //在sendRedict中url前必须加上当前web程序的路径名..... response.sendRedirect(request.getContextPath()+"/fail.html"); }