Accessing the JSP and HTML files under Web_inf

Source: Internet
Author: User

How do I get the servlet to access a Web page or JSP file under Web-inf? Because Web-inf, the application server refers to it as a banned directory, which is not accessible directly in the browser.
Because of this, you can have a servlet access, such as Web-inf under the a.jsp can be used Request.getrequestdispatcher ("/web-inf/a.jsp"). Forward (Request,response); For dispatch access. But if there are a.htm under Web-inf, then use Request.getrequestdispatcher ("/web-inf/a.htm"). Forward (Request,response);

At first I thought it was strange. Then think about, JSP is also a servlet, will automatically compile, so the work directory will have/web-inf/a$jsp.class type, so there is a clue, so that the application server can compile. htm, such as a$ Htm.class. Hold the idea and start to do it

Conf/web under Tomcat, find the way to access the JSP,

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

So add the following

<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>

Results: All OK, access to a.htm, and a.html under work/web-inf/have A$htm.class,a$html.class generated </

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.