目标不可达,标识符解析为空



我已经看过了:

目标不可达,标识符在JSF 2.2中解析为空

目标不可达,标识符'验证器'解析为null"在SEAM

Java EE 6: Target Unreachable, identifier 'helloBean'解析为null

目标不可达,标识符"Bean名称";解析为null

目标不可达,标识符"Bean名称";解析为null

JSF:/index.xhtml @12,80 value="#{LoginBean.username}":目标不可达,标识符'LoginBean'解析为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  

但是有两个字符串具有相同的get和set,但没有警告。

您当前的代码有相当多的错误:

  1. 您使用了错误的JSF注释

  2. 您没有使用jsf标准标记。用途:

    • <h:head/>而不是<head>(这是jsf中大多数ajax功能所必需的)。如果没有它,支持ajax所需的javascript就不能包含在页面
    • 中。
    • <h:body>代替<body>

HTTP-500表示您的代码中存在实际的错误。

不要害怕500个错误码。只要仔细阅读堆栈跟踪即可。有一些错误在你的代码,如空指针异常。请检查这个代码并告诉结果。

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标签和注释

尝试使用不同的注释

import javax.faces.bean.ManagedBean;

代替Java EE 6的

import javax.annotation.ManagedBean;

相关内容

  • 没有找到相关文章

最新更新