2017-06-13 188 views
0

我在WEB-INF文件夹外有几个文件夹,这些文件夹包含jsp文件。阻止访问WEB_INF外的内容(jsp文件)

Sample Directory structure: 
-WEB-INF 
-DirA 
    -a.jsp 
    -b.jsp 
-DirB 
-c.jsp 
-d.jsp 

如何阻止用户访问所述静态文件(JSP)的所述WEB-INF文件夹以外的websphare 8服务器?

回答

0

您将需要在web.xml中指定安全约束。一个好的教程Web应用程序的安全性可以在这里找到: http://docs.oracle.com/javaee/5/tutorial/doc/bncbx.html

基本上,你需要这样的事情在你的web.xml:

<security-constraint> 
    <display-name>SecurityConstraintForDirA</display-name> 
    <web-resource-collection> 
    <web-resource-name>DirAResources</web-resource-name> 
    <url-pattern>/DirA/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
    <role-name>dirAUsers</role-name> 
    </auth-constraint> 
    <user-data-constraint> 
    <transport-guarantee>NONE</transport-guarantee> 
    </user-data-constraint> 
</security-constraint> 

希望这有助于安迪

+0

感谢。我之前检查过这个。因为我在WEB-INF目录外有多个文件夹。如果我想用这种方式,我需要在web.xml中添加每个文件夹。有没有其他的方式来阻止它在websphare设置? – jAnA

+0

此链接可能也是有用的: https://www.ibm.com/developerworks/websphere/techjournal/1303_lansche/1303_lansche.html 请注意,您可以在安全约束中指定多个url模式 - 这样您就可以拥有一个所有目录(即/ *)或某个子集(即/ DirA,/ DirB,/ DirC)的安全约束。 我不知道任何特定于WebSphere的方法来保护多个目录。 –