简体   繁体   English

<h:outputText> index.xhtml无法在浏览器中呈现

[英]<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 我在用

  1. Eclipse JAVA EE IDE (Luna Service Release 1 (4.4.1)) Eclipse JAVA EE IDE(Luna服务版本1(4.4.1))
  2. apache-tomcat-7.0.57 apache-tomcat-7.0.57
  3. Maven 3.2.5 Maven的3.2.5
  4. Java version 1.7 Java 1.7版

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.

相关问题 为视图/index.xhtml配置的ICEfaces,但需要h:head和h:body组件 - ICEfaces configured for view /index.xhtml but h:head and h:body components are required 错误呈现视图[/index.xhtml] java.lang.NumberFormatException:对于输入字符串:“” - Error Rendering View[/index.xhtml] java.lang.NumberFormatException: For input string: "" 在ExternalContext中找不到/index.xhtml作为资源 - /index.xhtml Not Found in ExternalContext as a Resource Primefaces 和 Jboss 的 index.xhtml 404 错误 - index.xhtml 404 error with Primefaces and Jboss 404 /index.xhtml在ExternalContext中找不到作为资源 - 404 /index.xhtml Not Found in ExternalContext as a Resource JSF index.xhtml并重定向到faces动作 - JSF index.xhtml and redirect to faces action 在JSF中找不到index.xhtml资源 - index.xhtml resource not found in JSF h:outputLink指向http:// localhost:8080 / Org / faces / gone4.com / faces / index.xhtml而不是got4.com - h:outputLink points to http://localhost:8080/Org/faces/gone4.com/faces/index.xhtml instead of gone4.com 无法找到或提供资源,/ Directory1 / Myproject / index.xhtml - Unable to find or serve resource, /Directory1/Myproject/index.xhtml jsf2-javax.el.PropertyNotFoundException: /index.xhtml 除外 - jsf2-javax.el.PropertyNotFoundException: /index.xhtml except
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM