Transferred from: http://blog.csdn.net/eidolon8/article/details/7050114
Method 1:
The JSP in the original Web-inf is not accessible through the address bar. So safe. If you want to access the JSP files in this folder you need to configure the servlet format in the project's Web. xml file. As follows:
[HTML]View Plaincopy
- <servlet>
- <servlet-name>runtain</servlet-name>
- <jsp-file>/web-inf/inf.jsp</jsp-file>
- </servlet>
- <servlet-mapping>
- <servlet-name>runtain</servlet-name>
- <url-pattern>/xxx</url-pattern>
Access Address: http://localhost:8080/runtain/xxx
You can see the content!
Method 2:<jsp:forward page = "/web-inf/jsp/test/test.jsp"/>
Method 3:request.getrequestdispatcher ("/web-inf/a.jsp"). Forward (Request,response);
How do I get a servlet to access a Web page or JSP file under Web-inf? Because Web-inf, the application server refers to it as a forbidden directory, which is inaccessible directly in the browser.
As a result, the servlet can be accessed, such as Web-inf under the a.jsp can be used Request.getrequestdispatcher ("/web-inf/a.jsp"). Forward (Request,response); For dispatch visits. But if there is a.htm under Web-inf, then use Request.getrequestdispatcher ("/web-inf/a.htm"). Forward (Request,response);
At first, I thought it was strange. Later think, JSP is actually also servlet, will automatically compile, so work directory will have/web-inf/a$jsp.class type, then have the clue, let application server can compile. htm, such as a$ Htm.class the idea, start doing it.
Under Tomcat, find the way to access the JSP, Conf/web,
[HTML]View Plaincopy
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.jsp</url-pattern>
- </servlet-mapping>
Then add the following
[HTML]View Plaincopy
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.htm</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>jsp</servlet-name>
- <url-pattern>*.html</url-pattern>
- </servlet-mapping>
Result: All OK, access to a.htm, and a.html in work/web-inf/have a$htm.class,a$html.class generated
"Reprint" Access to JSP files in the Web-inf directory