一:RequestDispatcher.forward()
是在服务器端起作用,当使用forward()时,Servlet engine 传递HTTP请求从当前的Servlet or jsp 到另外一个Servlet JSP 或普通HTML文件
可以进行参数传递 如:
RequestDispatcher rd = context.getRequestDispatcher("/jsp/forward.jsp?name=zhangsan");
RequestDispatcher rd = context.getRequestDispatcher("/F?name=jingjing");
重定向后浏览器地址栏URL不变
<p> 例:在servlet中进行重定向</p><p> </p><pre class="java" name="code">public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
ServletContext context = getServletContext();
//forward()到jsp
RequestDispatcher rd = context.getRequestDispatcher("/jsp/forward.jsp?name=zhangsan");
//forward()到令一个servlet F为servlet的url-pattern servlet也可进行参数传递
//RequestDispatcher rd = context.getRequestDispatcher("/F?name=jingjing");