日期:2014-05-17 浏览次数:20773 次
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); request.setAttribute("aa","dp"); request.getRequestDispatcher("rep").forward(request, response); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.println("跳转到RepServlet"); String ss = (String) request.getAttribute("aa"); System.out.println(ss); if (ss == null) { //一直执行这一句 out.println("跳转不能从请求获得数据"); }else { out.println(ss); } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); }