public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String username= request.getParameter("username"); HttpSession session = request.getSession(); session.setAttribute("username", username); //request.setAttribute("username", username);//一定要保存,OGNL才能获取${username} //或者直接在jsp页面中用<%=request.getParameter("username")获取,两种结果一样,但是后者有null request.getRequestDispatcher("/success.jsp").forward(request, response); //response.sendRedirect("/success.jsp");//会报错.原因不懂 }