java 未呈现 JSF 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16253366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JSF tags are not being rendered
提问by Dan Prince
I'm starting a JSF project (this is the first time I've used JSF) and I'm having problems with the tags being rendered. I'm developing in Eclipse and using TomCat as a server.
我正在启动一个 JSF 项目(这是我第一次使用 JSF)并且我在渲染标签时遇到了问题。我正在 Eclipse 中开发并使用 TomCat 作为服务器。
My login.jsp file: https://gist.github.com/code-curve/e7e557262d407dddd1f3
My web.xml file: https://gist.github.com/code-curve/52902b7605b780dea93f
Eclipse project structure: http://snag.gy/P8Sts.jpg
Server startup log: https://gist.github.com/code-curve/d1927a636052607ce16a
我的 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
I am accessing the file with this url: http://localhost:8080/DeutschAkademie/login.jsp
and
as I understand the <h:form>
tag should render as <form>
, but instead it's instead rendering as <h:form>
. Any ideas?
我正在使用这个 url 访问文件:http://localhost:8080/DeutschAkademie/login.jsp
据我所知,<h:form>
标签应该呈现为<form>
,但它反而呈现为<h:form>
. 有任何想法吗?
回答by Luiggi Mendoza
Two advices:
两个建议:
Update the URL pattern for Faces Servlet. The default configuration can be for
*.jsp
(no need to use*.faces
or something else. Still, I would recommend using*.xhtml
.JSF 2 works with Facelets, so you don't need to use old JSP anymore. By reading your login.jsp page content, you can just rename the extension from jsp to xhtml and it will work.
更新 Faces Servlet 的 URL 模式。默认配置可以是
*.jsp
(不需要使用*.faces
或其他东西。不过,我建议使用*.xhtml
.JSF 2 与 Facelets 一起工作,因此您不再需要使用旧的 JSP。通过阅读您的 login.jsp 页面内容,您只需将扩展名从 jsp 重命名为 xhtml 即可。
Based on these, the web.xmlwill look like this:
基于这些,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>
And having login.xhtml
file.
并有login.xhtml
档案。
To access to your page you will only need to write http://localhost:8080/DeutschAkademie/login.xhtml
in your browser address bar.
要访问您的页面,您只需要http://localhost:8080/DeutschAkademie/login.xhtml
在浏览器地址栏中输入即可。
Related:
有关的:
EDIT:
编辑:
Based on the picture of your project, the WEB-INF/libfolder is clean. You should drop the JSF 2 libraries there. Add them, recompile your project and try it again.
根据您项目的图片,WEB-INF/lib文件夹是干净的。您应该将 JSF 2 库放在那里。添加它们,重新编译您的项目并重试。
回答by Zack
When you create your project, the web.xml
will be generated for you and as default the servlet-mapping
inside of this file will look like that:
当您创建项目时,web.xml
将为您生成 并且默认情况下servlet-mapping
,此文件的内部将如下所示:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
It expect that you will put all your.xhtml
files under a folder called faces
.
So you can create this folder called faces
under WebContent
and put your .xhtml
files there and than call your application
.http://localhost:8080/DeutschAkademie/faces/login.xhtml
Or you can edit your web.xml
and change the servlet-ammping to
它希望您将所有.xhtml
文件放在一个名为faces
.
所以你可以创建这个名为faces
under 的文件夹WebContent
并将你的.xhtml
文件放在那里,然后调用你的应用程序
。http://localhost:8080/DeutschAkademie/faces/login.xhtml
或者您可以编辑您的web.xml
并将 servlet-ampping 更改为
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
and than call your application
. http://localhost:8080/DeutschAkademie/login.xhtml
Those Solutions have also been mentioned above.
而不是调用您的应用程序
。http://localhost:8080/DeutschAkademie/login.xhtml
上面也提到了这些解决方案。
回答by John Velandia
After addding <url-pattern>*.xhtml</url-pattern>
, ensure your files have extension .xhtml, otherwise will not work.
添加后<url-pattern>*.xhtml</url-pattern>
,确保您的文件扩展名为.xhtml,否则将无法工作。
回答by Lukas Eichler
Modify your web.xml to
将您的 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>
rename your file to login.xhtml
将您的文件重命名为 login.xhtml
open your file at http://localhost:8080/DeutschAkademie/faces/login.xhtml
打开你的文件 http://localhost:8080/DeutschAkademie/faces/login.xhtml