我是JSF的新手并且首先编写简单的jsf web应用程序.
带有.jsf的URL映射到WebContent中的.xhtml文件,但为什么我可以在Web浏览器中使用所有jsf标记打开.xhtml.怎么保护这个?
sta*_*ker 18
您可以为web.xml阻止所有请求添加安全约束*.xhtml.
<security-constraint>
<display-name>Restrict raw XHTML Documents</display-name>
<web-resource-collection>
<web-resource-name>XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint />
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 10
除了定义<security-constraint>来阻止直接访问.xhtml为正确地堆在这个问题回答文件,你也可以只改变<url-pattern>了的FacesServlet来自映射*.jsf到*.xhtml.
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
在JSF 1.x中,这常常以无限循环结束,但在JSF 2.x中不再存在.所以你可以调用/链接所有页面,.xhtml而不是摆弄不同的扩展.唯一的缺点是你不能在不调用的情况下显示"普通"的XHTML文件FacesServlet,但是这样的页面应该被命名.html:)