我有一个 Web 应用程序,最初是 JSF 应用程序,但已迁移到纯 HTML/JavaScript。我们现在正在彻底消除 JSF。
我们有物理文件 main.xhtml,它是由“main.jsf”请求的,其中 FacesServlet 在 web.xml 中使用 url 映射 *.jsf 声明。
我们已将内容移至 main.html,并在 main.xhtml 中放置元标记 REFRESH 以重定向到 main.html。
现在的问题是,即使我从 web.xml 中删除 FacesServlet,它仍然会将 main.jsf 的请求重定向到 main.xhtml。如果我将文件 main.xhtml 重命名为 main.jsf,请求 main.jsf 会给出 404,并且服务器日志显示找不到文件“main.jsp”。
现在的问题是:如果即使 web.xml 中没有 FacesServlet,它也将 *.jsf 重定向到 *.jsp 或 *.xhtml,那么是什么导致了这种重定向?
我使用的是 GlassFish 3.1.2.2。
最佳答案
在 Servlet 3.0+ 容器上使用 JSF 2.0+ 时,并且没有显式 FacesServlet
在webapp自己注册web.xml
,然后 FacesServlet
将在 webapp 启动期间自动注册到 URL 模式 /faces/*
, *.faces
和*.jsf
.
另请参阅其 javadoc :
This servlet must automatically be mapped if it is not explicitly mapped in
web.xml
orweb-fragment.xml
and one or more of the following conditions aretrue
.
A
faces-config.xml
file is found inWEB-INF
A
faces-config.xml
file is found in theMETA-INF
directory of a jar in the application's classpath.A filename ending in
.faces-config.xml
is found in theMETA-INF
directory of a jar in the application's classpath.The
javax.faces.CONFIG_FILES
context param is declared inweb.xml
orweb-fragment.xml
.The
Set
of classes passed to theonStartup()
method of theServletContainerInitializer
implementation is not empty.If the runtime determines that the servlet must be automatically mapped, it must be mapped to the following
<url-pattern>
entries.
/faces
*.jsf
*.faces
JSF 2.3 将添加 *.xhtml
该集的 URL 模式(在 Mojarra 2.2.11 中向后移植)。
如果您想停止此行为,并且无法消除触发器(例如仍然有 faces-config.xml
),那么最好的选择是显式注册 FacesServlet
上*.xhtml
在webapp自己的web.xml
。这将覆盖默认的自动注册 URL 模式。
关于jsf - 从 web.xml 中删除 FacesServlet 后,扩展名为 .jsf 的 URL 仍重定向到 .xhtml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32582696/