JSP restricted access-3 ways to protect pages

Source: Internet
Author: User

A. Web-inf Folder protection page

As is known to all, the Web-inf folder file is not directly accessible, so, in the development of the JSP page can be directly placed in the folder. Through the page forwarding mechanism, to access. (forwarding is an internal operation that can be accessed through a servlet)

Two. Web. XML Protection page

If you do not want to prevent direct page access through the Web-inf folder, you can protect the page through the security mechanism of Web. Xml.

To set a protected URL address through the <security-constraint> element

Specific operation:

In the Web. xml file, make the following settings:

<security-constraint>

<web-resource-collection>

<web-resource-name>no-acess</web-resource-name>

<url-pattern>/test/*</url-pattern>

</web-resource-collection>

<auth-constraint>

<role-name>admin</role-name>

</auth-constraint>

</security-constraint>

Description:<auth-constraint> defines a role named admin, and if the user is not given the role, then the protected page cannot be accessed directly.

However, because forwarding is an internal operation, the security restrictions mentioned above have no effect on forwarding .

Three. Configuring filter protection in Web. xml

Filters can be used to filter the URL addresses specified in the system. Can affect the forwarding mechanism of the application system, the specified pages and requests can be filtered by the filter.

JSP restrict Access-3 ways to protect pages

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.