请看文档对include方法的说明:Includes the content of a resource (servlet, JSP page, HTML file) in the response. In essence, this method enables programmatic server-side includes. 
The ServletResponse object has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored. The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of the ServletRequestWrapper or ServletResponseWrapper classes that wrap them.说白了,就是基于include的特殊性,这些东西都不能更改。你可以换成其他实现方式,比如iframe来包含。

解决方案 »

  1.   

    上面说的是无法改变response status code啊。我的是request,并用在servlet中用request.getRequestDispatcher("/servlet.do").include(request, response); 
    传用另一个servlet是可以拿到servletPath为/servlet.do,而在jsp中用不行。
      

  2.   

    我解决了。原来是放到了request 的 attribute里面.
    用request.getAttribute("javax.servlet.include.servlet_path");可以拿到