RequestDispatcher("path")
这个类具体是怎么用的,得到path/中的request有什么用处,还有forward()和include()方法,就更是不知道有什么用了......哪个高手可以告诉我吗。最好写个程序思路。

解决方案 »

  1.   

    String path="/index.jsp";//这是当前应用中一个绝对路径的urlservlet:
    RequestDispatcher dispatcher=getServletContext().getRequestDispatcher(path);
    jsp:
    RequestDispatcher dispatcher=application.getRequestDispatcher(path);all:
    dispatcher.forward();//转到path这个页面(不可以在这之前或之后有其它输出)
    dispatcher.include();//向浏览器输出path这个页面的执行结果(可以在这之前或之后有其它输出)
      

  2.   

    1、ServletRequest.getRequestDispatcher(String path)
    path可是绝对路径也可以是相对路径2、ServletContext.getRequestDispatcher(String path)
    path必须以"/"开头,代表context root3、另一个方法 ServletContext.getNameDispatcher(String name)
    参数并不是路径,而是其名称,如果有多个Servlet名称一样的,在web.xml进行配置区别4、以上方法回传一个RequestDispatcher对象,接着forward()或include()5、forward()和include()区别在于include()方法将HTTP请求转送给其他Servlet或jsp后,这个Servlet或jsp虽然可以处理请求,但是主导权还是原来的Servlet或jsp,就是被调用的Servlet或jsp如果产生任何HTTP回应,将会并入原来的HttpResponse对象
      

  3.   

    Okay,我在自己试试,先给分了。