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

发布于 2024-12-27 14:06:23 字数 1257 浏览 3 评论 0 原文

我安装了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 文件时,自动完成功能不起作用。 (即它不会自动完成。它曾经在我使用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 have Weblogic 10.3.5 installed. I deployed the JSF 2.0 war on the server. In my WebContent folder, I have *.xhtml and *.jsp files, which contain JSF2.0 xhtml and pure JSP code, respectively. When I navigate to http://localhost:7001/MyApp/NewFile123.xhtml, I get a 404 Not found error page. (Nothing informative on the Eclipse console). But http://localhost:7001/MyApp/NewFile.jsp works well and does what it's supposed to do.

I am not mixing JSF and JSP but just wanted to see if JSP is gonna work. I have the appropriate servlet-mapping for the XHTML files.

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

Another interesting thing, when I try to edit the *.xhtml files, the auto-complete doesn't work. (i.e it won't autocomplete <h:outp. It used to when I was using Weblogic 12.1 which has JSF2.0 out of the box.

Edit: Here is the relevant part of 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>

So why do I get a 404 when I try to navigate to a JSF page? Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿哥们儿 2025-01-03 14:06:23

我的类路径上也有这些:

  • 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 正常工作,另请参阅 此博客。以下是相关性的摘录:

  • 下载并安装最新的 Oracle WebLogic Server 11g Rel 之一1 (10.3.3) 来自 OTN 的安装程序。 (尝试一下 ZIP 安装程序。非常棒的轻量级!)
  • 创建一个新的示例域(随意命名)并启动管理服务器
  • 打开管理控制台 (http://localhost:7001/console/)
  • 部署 JSF 2.0 库(部署 - 安装 - wlserver_10.3\common\deployable-libraries\jsf-2.0.war
  • 找到您最喜欢的 JSF 2.0 示例(我将从 mojarra-2.0.2 发行版中获取guessNumber 内容)
  • 将 weblogic.xml 文件添加到 WEB-INF/ 文件夹,其中包含以下内容:

    
    ;
      <图书馆参考>
        <库名称>jsf
        <规范版本>2.0
        <实现版本>1.0.0.0_2-0-2
        <精确匹配>true
      
    
    

按照注释更新

我现在怀疑可能是项目设置的原因。我创建了一个动态 Web 项目并选择了 JSF 1.2。下一步,当它询问我 JSF 规范和实现时,我向他指出了那些 glassfish jsf2 jar。默认值为 1.2。也许我不应该这样做?

这可能会生成一个兼容 JSF 1.2 的faces-config.xml,这将强制 JSF 2.0 以 JSF 1.2 方式运行。您需要重新声明 根声明以符合 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">

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

Remove all those container-specific libraries from your /WEB-INF/lib. They do not belong there at all, the container already ships with them. Your /WEB-INF/lib should contain only the webapp-specific libraries which are not shipped with the container.

Your problem is most likely caused by the fact that Weblogic 1.0.3.5 is a Servlet 2.5 container which already ships with JSF 2.0, but that you're supplying a JSF 2.1 library which requires Servlet 3.0. I don't use Weblogic, but I've read that 1.0.3.x requires some specific steps to get JSF 2.0 to work, see also this blog. Here's an extract of relevance:

  • 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>
    

Update as per the comments:

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?

That might have generated a JSF 1.2 compliant faces-config.xml which would force JSF 2.0 to run in JSF 1.2 modus. You need to redeclare the <faces-config> root declaration to comply 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">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文