如果我在web.xml中放置安全约束,我的Web应用程序将如何访问jsp文件

时间:2015-03-06 12:00:15

标签: java jsp iframe

<security-constraint>
    <web-resource-collection>
        <web-resource-name>JSP Files</web-resource-name>
        <description>No direct access to JSP files</description>
        <url-pattern>/pages/*</url-pattern>
        <http-method>POST</http-method>
        <http-method>GET</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description>No direct browser access to JSP files</description>
        <role-name>NobodyHasThisRole</role-name>
    </auth-constraint>
</security-constraint>

这个我放入我的web.xml以避免直接访问jsp页面。但是在我的应用程序放入后无法访问iframe中显示的jsp页面。

<iframe src="pages/home.jsp"  id="contentframe" name="contentframe"  scrolling="no"></iframe> 

结果显示在iframe中是“访问资源被拒绝”,而我希望我的index.jsp访问pages文件夹中的jsp页面但不能直接访问所有jsp页面

2 个答案:

答案 0 :(得分:0)

security-constraint定义http安全性,iframe作为普通的http请求,与任何内部操作无关,因此,如果您为页面定义安全性,则iframe调用会在您直接打开URL时起作用。

要隐藏jsp直接访问,必须将它们放在WEB-INF文件夹下,然后使用一些servlet映射来访问jsp资源。

答案 1 :(得分:0)

通常,要隐​​藏用户的jps文件,您可以将它们放在WEB-INF文件夹中,然后使用一些servlet使它们成为&#34; access&#34;视图。 SpringMVC是一个DispatcherServlet,它允许您使用ViewResolver。

但是,要更具体地回答您的问题,如果您想在iframe中打开资源,则需要定义the correct header(取决于您想要的内容)。在SpringMVC中定义标头的一种方法是使用XSSFilter。