原文链接
tian.jsp <%request.setAttribute("river","redwater"); request.setAttribute("country","daguaiwan"); %> <jsp:forward page="fengshan.jsp" />
donglan.jsp <%request.setAttribute("river","redwater"); request.setAttribute("country","daguaiwan"); %> <a href="fengshan.jsp">fengshan</a>
bama.jsp <%request.setAttribute("river","redwater"); request.setAttribute("country","daguaiwan"); response.sendRedirect("fengshan.jsp"); %>
fengshan.jsp <%=request.getAttribute("river")%><br/> <%=request.getAttribute("country")%>
servlettiane.jsp <%request.setAttribute("river","redwater"); request.setAttribute("country","daguaiwan"); %> <jsp:forward page="/tiane" />
servletbama.jsp <%request.setAttribute("river","redwater"); request.setAttribute("country","daguaiwan"); response.sendRedirect("/ForwardRedirect/tiane"); %>
Tiane.java publicclass Tiane extends HttpServlet { publicvoid doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // response.sendRedirect("/ForwardRedirect/fengshan.jsp"); this.getServletConfig().getServletContext() .getRequestDispatcher("/fengshan.jsp").forward(request, response); } publicvoid doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } }
再在web.xml中配置servlet: <servlet> <servlet-name>tiane</servlet-name> <servlet-class>com.dvnchina.test.Tiane</servlet-class> </servlet> <servlet-mapping> <servlet-name>tiane</servlet-name> <url-pattern>/tiane</url-pattern> </servlet-mapping>