JSF标签没有被呈现



我正在启动一个JSF项目(这是我第一次使用JSF),并且我在呈现标记时遇到了问题。我在Eclipse中开发,使用TomCat作为服务器。

  • 我的login.jsp文件:https://gist.github.com/code-curve/e7e557262d407dddd1f3

  • 我的web.xml文件:https://gist.github.com/code-curve/52902b7605b780dea93f

  • Eclipse项目结构:http://snag.gy/P8Sts.jpg

  • 服务器启动日志:https://gist.github.com/code-curve/d1927a636052607ce16a

我用这个url访问文件:http://localhost:8080/DeutschAkademie/login.jsp和正如我所理解的<h:form>标签应该呈现为<form>,但相反,它呈现为<h:form>。什么好主意吗?

两个建议:

  1. 更新Faces Servlet的URL模式。默认配置可以是*.jsp(不需要使用*.faces或其他配置)。尽管如此,我还是建议使用*.xhtml

  2. JSF 2与Facelets一起工作,因此您不再需要使用旧的JSP。通过阅读您的login.jsp页面内容,您可以将扩展名从jsp重命名为xhtml,这样就可以工作了。

基于这些,web.xml看起来像这样:
<web-app>
    <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>
    <welcome-file-list>
        <welcome-file>login.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

login.xhtml文件。

要访问您的页面,您只需要在浏览器地址栏中写入http://localhost:8080/DeutschAkademie/login.xhtml

相关:

    为什么我的jsf标签不能工作?

编辑:

根据项目的图片,WEB-INF/lib文件夹是干净的。您应该在这里放下JSF 2库。添加它们,重新编译项目并再次尝试。

当您创建您的项目时,web.xml将为您生成,默认情况下,该文件中的servlet-mapping将看起来像这样:

 <servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
 <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>

它期望你将所有.xhtml文件放在一个名为faces的文件夹下。
所以你可以在WebContent下创建一个名为faces的文件夹,把你的.xhtml文件放在那里,然后把你的应用程序命名为http://localhost:8080/DeutschAkademie/faces/login.xhtml 。或者您可以编辑web.xml并将servlet映射更改为

 <servlet-mapping>
 <servlet-name>Faces Servlet</servlet-name>
 <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>

,然后调用应用程序http://localhost:8080/DeutschAkademie/login.xhtml

添加<url-pattern>*.xhtml</url-pattern>后,确保您的文件扩展名为.xhtml,否则将无法工作

将web.xml修改为

<web-app>
<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>*.faces</url-pattern>
<url-pattern>/faces/</url-pattern>
</servlet-mapping>
</web-app>

将文件重命名为login.xhtml

打开http://localhost:8080/DeutschAkademie/faces/login.xhtml

最新更新