如何避免用户访问JSF中的.xhtml页面?
我是 JSF 新手,首先编写简单的 jsf Web 应用程序。
带有 .jsf 的 URL 映射到 WebContent 中的 .xhtml 文件,但为什么我可以在 Web 浏览器中使用所有 jsf 标签打开 .xhtml。如何保护这个?
I am new to JSF and writing first simply jsf web app.
URL with .jsf are mapping to .xhtml files in WebContent but why I can open .xhtml in web browser with all jsf tags. How to protect this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以向
web.xml
添加安全约束,阻止对*.xhtml
的所有请求。You could add a security constraint to your
web.xml
blocking all requests to*.xhtml
.除了定义
来阻止直接访问.xhtml
文件(正如 Stacker 在此问题上正确回答的那样)之外,您还可以更改
从FacesServlet
的*.jsf
映射到*.xhtml
。在 JSF 1.x 中,这通常会导致无限循环,但在 JSF 2.x 中不再如此。因此,您可以将所有页面调用/链接为
.xhtml
,而无需摆弄不同的扩展名。唯一的缺点是,如果不调用FacesServlet
,您将无法显示“纯”XHTML 文件,但无论如何,这样的页面应该命名为.html
:)Apart from defining a
<security-constraint>
to block direct access to.xhtml
files as correctly answered by Stacker on this question, you could also just change the<url-pattern>
of theFacesServlet
mapping from*.jsf
to*.xhtml
.In JSF 1.x this used to end up in an infinite loop, but in JSF 2.x not anymore. So you could just call/link all pages as
.xhtml
without fiddling with different extensions. The only disadvantage is that you won't be able to display a "plain" XHTML file without invoking theFacesServlet
, but such a page should be named.html
anyway :)在 GAE 上,您需要两件事:
On GAE you need two things:
您可以使用 servlet 过滤器
You can use a servlet filter
据我的经验,mk761203的答案在为谷歌应用程序引擎和服务器面孔设置项目时绝对有帮助。如果不排除这些文件,GAE 会自动将扩展名为 .xhtml 的文件解释为静态文件,这些文件由 google 服务器场的专用服务器提供服务。请在此处阅读更多信息:https://developers.google.com/appengine/docs /java/config/appconfig#Static_Files_and_Resource_Files
as far as i experienced it, the answer of mk761203 is definitely helpful when setting up a project for google app engine and server faces. without the exclusion of this files, the GAE automatically interpets the files with the .xhtml extension as static files which get served by dedicated servers from googles server farm. read more here: https://developers.google.com/appengine/docs/java/config/appconfig#Static_Files_and_Resource_Files