[英]Helloworld JSF2.0 Page is not rendering as html tags
Im a Totally new in Java and JSF. 我是Java和JSF的新手。 I'm using eclipse Indigo and Tomcat 6.0.3 and JSF 2.0.
我正在使用Eclipse Indigo和Tomcat 6.0.3和JSF 2.0。
When i run the Page in Browser, I just get an empty page, but i could the elements in firebug that it is still in JSF tags itself. 当我在浏览器中运行Page时,我只会得到一个空页面,但是我可以将Firebug中的元素仍保留在JSF标签本身中。 It is not rendering in html..
它不在html中呈现。
This is my web.xml 这是我的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>/app/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>pages/AddUser.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
I have Tried to add the url-pattern
as *.xhtml
but it still doesnt work. 我试图将
url-pattern
添加为*.xhtml
但仍然无法正常工作。
This is my xhtml file.. 这是我的xhtml文件。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Add New User Form</title>
</h:head>
<h:body>
<f:view>
<h:form>
<h:outputText value="Age"></h:outputText>
</h:form>
</f.view>
</h:body>
The problem is that the pattern of the JSF servlet is <url-pattern>/app/*</url-pattern>
. 问题在于JSF servlet的模式是
<url-pattern>/app/*</url-pattern>
。 Change the pattern to *.jsf
and access http://localhost:8080/yourXhtmlFileName.jsf
. 将模式更改为
*.jsf
并访问http://localhost:8080/yourXhtmlFileName.jsf
。
Try localhost:8080/app/ContactFormJSF. 尝试localhost:8080 / app / ContactFormJSF。 It depend on the
<url-pattern>
you configured in your web.xml. 它取决于您在web.xml中配置的
<url-pattern>
。 You URL should match the pattern so that the Faces Servlet can handle your request and render the page. 您的URL应该与模式匹配,以便Faces Servlet可以处理您的请求并呈现页面。
There is a chance in missing libraries under WEB-INF/lib
folder.. WEB-INF/lib
文件夹下的库可能会丢失。
In Most of the cases the required jars will not configured properly 在大多数情况下,所需的jar无法正确配置
WEB-INF/lib
directory WEB-INF/lib
目录下 Did you use following tag on your web.xml file ? 您是否在web.xml文件中使用了以下标记?
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>//you are missing "faces"
</welcome-file-list>
Full xml file: 完整的xml文件:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/pages/index.xhtml</welcome-file>
</welcome-file-list>
Updated 更新
The element type f:view
must be terminated by the matching end-tag </f:view>
. 元素类型
f:view
必须以匹配的结束标记</f:view>
终止。
<f:view>
<h:form>
<h:outputText value="Age"></h:outputText>
</h:form>
</f.view> //Here it should be </f:view>
You are using .
您正在使用
.
you should use :
. 您应该使用
:
Following is the corrected format : 以下是更正的格式:
<f:view>
<h:form>
<h:outputText value="Age"></h:outputText>
</h:form>
</f:view>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.