请看文档对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来包含。
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来包含。
传用另一个servlet是可以拿到servletPath为/servlet.do,而在jsp中用不行。
用request.getAttribute("javax.servlet.include.servlet_path");可以拿到