我已经看过了那些:
Target Unreachable, identifier resolved to null in JSF 2.2
"Target Unreachable, identifier 'authenticator' resolved to null" in SEAM
Java EE 6: Target Unreachable, identifier 'helloBean' resolved to null
Target Unreachable, identifier "Bean Name" resolved to null
Target Unreachable, identifier "Bean Name" resolved to null
http://www.coderanch.com/t/598907/JSF/java/Target-unreachable-identifier-resolved-null
但他们都没有为我工作。
Login.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login Page</title>
</head>
<body>
<h:form prependId="false">
<h3>WELLCOME</h3>
<br />
<h3>Enter</h3>
<table>
<tr>
<td><h3>Name</h3></td>
<td><h:inputText value="#{user.name}" id="name" /></td>
</tr>
<tr>
<td><h3>password</h3></td>
<td><h:inputSecret value="#{user.password}" id="password" /></td>
</tr>
</table>
<h:commandButton value="Login">
<f:ajax execute="name password" render="out" />
</h:commandButton>
<h3>
<h:outputText id="out" value="#{user.greeting}" />
</h3>
</h:form>
</body>
</html>
User.java:
import java.io.Serializable;
import javax.annotation.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class User implements Serializable {
private String name;
private String password;
private String greeting;
public String getGreeting() {
if (name.length() == 0)
return "";
else
return "Welcome to JSF2 + Ajax, " + name + "!";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
我没有配置那些web.xml,因为jsf2.2就像我所知道的那样。
<?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>Ajax</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
配置面:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
单击按钮时出现错误:
HTTP Status 500 - /Login.xhtml @17,78 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null
--------------------------------------------------------------------------------
type Exception report
message /Login.xhtml @17,78 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'user' resolved to null
at org.apache.el.parser.AstValue.getTarget(AstValue.java:98)
at org.apache.el.parser.AstValue.getType(AstValue.java:82)
at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:172)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这个警告:
Typee value of the field User.greeting is not used
但是有2个字符串具有相同的get和set但没有警告。
我使用tomcat 7.0.54。
答案 0 :(得分:3)
不要害怕500错误代码。只是仔细阅读堆栈跟踪。您的代码中存在一些错误,例如Null Pointer Exception。请检查此代码并告知结果。
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class User implements Serializable {
private String name;
private String password;
private String greeting;
/**
* @return
*/
public String getGreeting() {
if (name == null ||name.length() == 0)
return "";
else
return "Welcome to JSF2 + Ajax, " + name + "!";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
请注意@kolossus的答案并使用标准的jsf标签和注释
答案 1 :(得分:2)
尝试使用不同的注释
import javax.faces.bean.ManagedBean;
而不是Java EE 6的
import javax.annotation.ManagedBean;
答案 2 :(得分:2)
您当前的代码存在一些问题:
您没有使用JSF标准代码。使用:
<h:head/>
代替<head>
(这是jsf中大多数ajax功能所必需的。如果没有它,支持ajax的必要javascript不能包含在页面中<h:body>
代替<body>
HTTP-500表示代码中存在实际错误。