如何在URL中使用.jsf扩展名? [英] How to use .jsf extension in URLs?
问题描述
我正在开发JSF 2 Web应用程序.对于威信,我希望每个URL都以.jsf
扩展名结尾.现在,它以.xhtml
结尾.如果将其直接更改为Web浏览器地址栏中的.jsf
,则会显示HTTP 500错误.
I'm developing a JSF 2 web application. For prestige purpouses I would like that every URL ends with .jsf
extension. Now it ends with .xhtml
. If I change it directly to .jsf
in web browser address bar, then a HTTP 500 error is shown.
如何将其设置为.jsf
?
推荐答案
JSF页面的URL模式由web.xml
中FacesServlet
的<servlet-mapping>
指定.正如您所提到的,.xhtml
可以正常工作,您显然已对其进行了如下配置:
The URL pattern of JSF pages is specified by <servlet-mapping>
of the FacesServlet
in web.xml
. As you mentioned that .xhtml
works fine, you have apparently configured it as follows:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
您需要相应地更改<url-pattern>
以获得所需的虚拟URL扩展名.
You need to change the <url-pattern>
accordingly to get the desired virtual URL extension.
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
实际上,这是您需要更改以实现具体功能要求的所有内容.
That's all you need to change in order to achieve the concrete functional requirement, really.
但是,这将带来一个安全问题.现在,当将URL中的扩展名从.jsf
更改为.xhtml
时,最终用户可以看到原始的Facelets文件源代码.您可以通过在web.xml
上添加以下安全约束来防止这种情况:
However, this puts a security problem open. The enduser can now see the raw Facelets file source code when changing the extension in the URL back from .jsf
to .xhtml
. You can prevent this by adding the following security constraint to web.xml
:
<security-constraint>
<display-name>Restrict access to Facelets source code.</display-name>
<web-resource-collection>
<web-resource-name>Facelets</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
这篇关于如何在URL中使用.jsf扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!