[英]<h:outputText> of index.xhtml not rendering in the browser
I am a newbie in JAVA EE.My issue is that the tag h:outputText not rendering in the browser. 我是JAVA EE的新手,我的问题是标签h:outputText没有在浏览器中呈现。 Iam using
我在用
JAR files included in library: junit3.8.1, jsf-api-2.1.13,jsf-impl-2.1.12,javax.servlet-api-3.0.1 库中包含的JAR文件: junit3.8.1,jsf-api-2.1.13,jsf-impl-2.1.12,javax.servlet-api-3.0.1
Following is my web.xml 以下是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>jsfexample</display-name>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
pom.xml pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javacodegeeks.snippets.enterprise</groupId>
<artifactId>jsfexample</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jsfexample Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>jsfexample</finalName>
</build>
</project>
index.xhtml index.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JavaCodeGeeks</title>
</h:head>
<h:body>
<b>Check B tag</b>
<h:outputText value="#{helloWorldBean.msg}" />
</h:body>
</html>
JAVABEAN-helloWorld.java JAVABEAN-helloWorld.java
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="helloWorldBean")
@RequestScoped
public class HelloWorldBean {
public String msg="test";
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
@PostConstruct
private void init() {
msg = "Hello World!! JFS example.. ";
}
}
Please Let me know why the Tag is not rendering.Thanks in advance. 请让我知道为什么标记无法呈现。谢谢。
In fact it's nicer to put the servlet mapping in web.xml as follows 实际上,最好将servlet映射放在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>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
So you tell your applicication that any xhtml file called wirh prefix faces/ should be rendered by the faces Servlet. 因此,您告诉您的应用程序,应该由faces Servlet渲染任何名为wirh prefixfaces /的xhtml文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.