五、ServletContext和ServletRequest都能得到RequestDispatcher区别 1、ServletContext RequestDispatcher getRequestDispatcher(String path):path必须以"/"开头,代表当前的应用。这种写法,叫做绝对路径写法。 2、ServletRequest RequestDispatcher getRequestDispatcher(String path): path可以以"/"开头:代表当前的应用。这种写法,叫做绝对路径写法。 也可以不以"/"开头:代表相对路径。 //包含:元组件 public class ServletDemo3 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter pout= response.getWriter(); pout.write("安徽黄梅戏"); RequestDispatcher rd=request.getRequestDispatcher("/servlet/ServletDemo4"); rd.include(request, response); response.setContentType("text/html;charset=UTF-8"); PrintWriter pout= response.getWriter(); pout.write("不错哦 我喜欢");
|