zoukankan      html  css  js  c++  java
  • jsp限制访问

    一.WEB-INF文件夹保护页面

     众所周知,web-inf文件夹的文件是不能直接访问的,所以,在开发的时候可以直接将jsp页面放入该文件夹中。通过页面转发机制,来访问。(转发是一个内部操作,可以通过Servlet对其进行访问)

    二.web.xml保护页面

     如果不想通过WEB-INF文件夹防止页面直接访问,可以通过web.xml的安全机制,实现页面的保护作用。

     通过<security-constraint>元素设置受保护的url地址

         具体操作:

             在web.xml文件中进行如下设置:

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

              说明:<auth-constraint>定义了一个名为admin的角色,如果用户没被赋予这个角色,那么就不能直接访问受保护的页面了.

                    然而,因为转发是一个内部操作,所以,上面所讲的安全限制对转发并没有任何影响

    三.在web.xml中配置过滤器保护

          过滤器可以对系统中指定的url地址进行过滤。可以影响到应用系统的转发机制,对指定的页面和请求都能被过滤器过滤。

       

       

  • 相关阅读:
    恭介的法则
    229. Majority Element II
    169. Majority Element
    233. Number of Digit One
    172. Factorial Trailing Zeroes
    852. Peak Index in a Mountain Array
    162. Find Peak Element
    34. Find First and Last Position of Element in Sorted Array
    81. Search in Rotated Sorted Array II
    33. Search in Rotated Sorted Array
  • 原文地址:https://www.cnblogs.com/xiaowei-blog/p/4039608.html
Copyright © 2011-2022 走看看