我正在构建一个小型的hello world JSF应用程序。
我的index.xhtml如下
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<body>
Hello user.
<h:form>
<h:inputText value="#{test.value}"></h:inputText>
<h:commandButton value="Enter" action="welcome"></h:commandButton>
</h:form>
</body>
</html>
我的welcome.xhtml如下
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<h2>Welcome #{test.value}</h2>
</body>
</html>
我的托管bean如下
package com.test.testclass;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class Test {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
我的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"
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>Test Project</display-name>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- Faces Servlet -->
<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>
</web-app>
My gradle build file is as follows
buildscript {
// Repositories for libraries needed for building:
repositories {
mavenCentral()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
plugins {
id 'war'
}
war {
webInf {
from "WebContent/WEB-INF"
}
from("WebContent") {
include "index.xhtml"
}
outputs.upToDateWhen {
false
}
}
repositories {
mavenCentral()
maven {
url "http://download.java.net/maven/2/"
url "http://repository.primefaces.org/"
}
}
dependencies {
def jsfApi = "javax.faces:javax.faces-api:2.2"
def atmosphereRuntime = "org.atmosphere:atmosphere-runtime:2.4.9"
compile \
jsfApi,
atmosphereRuntime
providedCompile \
"javax:javaee-api:7.0",
"javax.servlet:javax.servlet-api:3.1.0",
"org.glassfish:javax.json:1.+"
}
task deploy(type: Copy) {
description "Deploys the test application."
from war.outputs
into System.env.DEPLOY_DIR
outputs.upToDateWhen { false }
}
当我在索引页面输入一个字符串并按Enter
时,我收到以下错误HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: /index.xhtml @9,38 value="#{test.value}": Target Unreachable, identifier 'test' resolved to null
root cause
javax.el.PropertyNotFoundException: /index.xhtml @9,38 value="#{test.value}": Target Unreachable, identifier 'test' resolved to null
root cause
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'test' resolved to null
note The full stack traces of the exception and its root causes are available in the "" logs.
""
后端bean以某种方式设置为null。我究竟做错了什么。请帮忙。