java - JSF2.0 - *.xhtml 页面给出 404-NotFound 但 *.jsp 工作正常吗?

标签 java jsp jsf jakarta-ee weblogic

我安装了 Weblogic 10.3.5。我在服务器上部署了 JSF 2.0 war。在我的WebContent文件夹中,我有 *.xhtml 和 *.jsp 文件,它们分别包含 JSF2.0 xhtml 和纯 JSP 代码。当我导航到http://localhost:7001/MyApp/NewFile123.xhtml时,我得到一个404 Not found错误页面。 (Eclipse 控制台上没有任何信息)。但是http://localhost:7001/MyApp/NewFile.jsp工作得很好并且做了它应该做的事情。

我没有混合 JSF 和 JSP,只是想看看 JSP 是否能工作。我有适合 XHTML 文件的 servlet 映射。

我的类路径上也有这些:

  • glassfish.el_1.0.0.0_2-2.jar

  • glassfish.jsf_1.0.0.0_2-1-5.jar

  • glassfish.jSTL_1.2.0.2.jar

  • javax.servlet_1.0.0.0_2-5.jar

另一件有趣的事情是,当我尝试编辑 *.xhtml 文件时,自动完成功能不起作用。 (即它不会自动完成 <h:outp 。以前当我使用 Weblogic 12.1 时,它具有开箱即用的 JSF2.0 。

编辑:这是 web.xml 的相关部分

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

那么当我尝试导航到 JSF 页面时为什么会收到 404 错误?有什么建议吗?

最佳答案

I also have these on my classpath:

  • glassfish.el_1.0.0.0_2-2.jar
  • glassfish.jsf_1.0.0.0_2-1-5.jar
  • glassfish.jstl_1.2.0.2.jar
  • javax.servlet_1.0.0.0_2-5.jar

/WEB-INF/lib 中删除所有这些特定于容器的库。它们根本不属于那里,容器已经随它们一起运输了。您的/WEB-INF/lib包含容器未附带的特定于 Web 应用程序的库。

您的问题很可能是由于 Weblogic 1.0.3.5 是一个 Servlet 2.5 容器,它已经随 JSF 2.0 一起提供,但您提供的 JSF 2.1 库需要 Servlet 3.0。我不使用 Weblogic,但我了解到 1.0.3.x 需要一些特定步骤才能使 JSF 2.0 正常工作,另请参阅 this blog 。以下是相关性摘录:

  • Download and install one of the latest Oracle WebLogic Server 11g Rel 1 (10.3.3) Installers from OTN. (Give the ZIP Installer a try. Aweseome lightweight!)
  • Create a new sample domain (call it whatever you want) and start the admin server
  • Open the administration console (http://localhost:7001/console/)
  • deploy the JSF 2.0 library (Deployments - Install - wlserver_10.3\common\deployable-libraries\jsf-2.0.war
  • Find your favorite JSF 2.0 sample (I'll take the guessNumber thing from the mojarra-2.0.2 distribution)
  • Add a weblogic.xml file to the WEB-INF/ folder with the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-web-app>
      <library-ref>
        <library-name>jsf</library-name>
        <specification-version>2.0</specification-version>
        <implementation-version>1.0.0.0_2-0-2</implementation-version>
        <exact-match>true</exact-match>
      </library-ref>
    </weblogic-web-app>
    
<小时/>

根据评论更新:

I now suspect that it may be because of the project settings. I created a Dynamic Web Project and chose JSF 1.2. On the next step, where it asked me for the JSF specification and implementation, I pointed him to those glassfish jsf2 jars. The default was 1.2. Maybe I shouldn't have done that?

这可能会生成符合 JSF 1.2 标准的 faces-config.xml这将强制 JSF 2.0 以 JSF 1.2 方式运行。您需要重新声明<faces-config>根声明以符合 JSF 2.0。

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

关于java - JSF2.0 - *.xhtml 页面给出 404-NotFound 但 *.jsp 工作正常吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8878314/

相关文章:

java - 作为过程的功能的动态(树形)结构(以及Clojure中的实现)

java - 如何将列表发送到请求它的 jsp?

java - Java Simple Captcha Builder 放在哪里?

jsf - 查看两个不同 portlet 之间的导航?

css - 如何将滚动条添加到数据表?

Java SQL 异常

java - 如何使用 Java 对 AWS S3 SDK 的 getObject 方法进行单元测试?

java - 根据另一个下拉列表选择填充下拉列表

java - 尝试调用 servlet 时遇到错误 404

jsf - Bean 验证 VS JSF 验证