"Reprint" Access to JSP files in the Web-inf directory

Source: Internet
Author: User

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
  1. <servlet>
  2. <servlet-name>runtain</servlet-name>
  3. <jsp-file>/web-inf/inf.jsp</jsp-file>
  4. </servlet>
  5. <servlet-mapping>
  6. <servlet-name>runtain</servlet-name>
  7. <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
    1. <servlet-mapping>
    2. <servlet-name>jsp</servlet-name>
    3. <url-pattern>*.jsp</url-pattern>
    4. </servlet-mapping>

Then add the following

[HTML]View Plaincopy
  1. <servlet-mapping>
  2. <servlet-name>jsp</servlet-name>
  3. <url-pattern>*.htm</url-pattern>
  4. </servlet-mapping>
  5. <servlet-mapping>
  6. <servlet-name>jsp</servlet-name>
  7. <url-pattern>*.html</url-pattern>
  8. </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

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.