jsf - 从 web.xml 中删除 FacesServlet 后,扩展名为 .jsf 的 URL 仍重定向到 .xhtml

标签 jsf glassfish facesservlet

我有一个 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 or web-fragment.xml and one or more of the following conditions are true.

  • A faces-config.xml file is found in WEB-INF

  • A faces-config.xml file is found in the META-INF directory of a jar in the application's classpath.

  • A filename ending in .faces-config.xml is found in the META-INF directory of a jar in the application's classpath.

  • The javax.faces.CONFIG_FILES context param is declared in web.xml or web-fragment.xml.

  • The Set of classes passed to the onStartup() method of the ServletContainerInitializer 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/

相关文章:

java - 向客户推荐 Glassfish

jsf-2 - FacesServlet 无法在 Web 片段中工作

java - 将 jsf web.xml 中的页面名称与文件名解耦

java - java服务器面临el的空控制

javascript - 当同一 View 中有两个图表时,如何独立显示或隐藏 Primefaces 图表图例?

jsf - 阻止 p :commandButton displayed on a p:confirmDialog in addition to displaying a dynamic message on the dialog

css - 我如何更改 JSF 文件的背景

memory - aws内存使用率高

java - 当我正确验证时,HTTP 禁止我访问指定资源 - JavaEE