jsf – 警告:/index.xhtml @ 18,82 value =“#{loginBean.email}”:目标无法访问,标识符’loginBean’已解析为null

前端之家收集整理的这篇文章主要介绍了jsf – 警告:/index.xhtml @ 18,82 value =“#{loginBean.email}”:目标无法访问,标识符’loginBean’已解析为null前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable9个
我是JSF的新手,我得到了这个错误,但我不知道如何修复它.
我在网上看了一些类似的问题,但没有一个能解决我的问题.

在这里我的课程:

的index.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://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      lang="en-us">
    <h:head>
        <title>Welcome </title>
    </h:head>
    <h:body>
        <center>
            <p:outputLabel><h1>Welcome</h1></p:outputLabel>
            <br/>
            <h:form id="loginForm">
            <p:panel id="loginPanel" header="Login" style="width: 360px;">
                <p:panelGrid columns="2">
                    <p:outputLabel id="email_outputText" value="Email" for="email_inputText"/>
                    <p:inputText id="email_inputText" value="#{loginBean.email}"></p:inputText>
                    <p:outputLabel id="password_outputText" value="Password" for="password_inputText"/>
                    <p:password id="password_inputText" value="#{loginBean.password}" Feedback="false"></p:password>
                </p:panelGrid>    
                    <br/>
                    <p:commandButton action="#{loginBean.MD5}" value="Login" update="loginForm"></p:commandButton>  
            </p:panel>
        </h:form>
        </center>
    </h:body>
</html>

LoginBean.java

package beans.controller;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;

@ManagedBean(value="loginBean")
@SessionScoped
public class LoginBean implements Serializable{

    /**
     * attribute that will contain the password input by the user
     */
    private String password;
    /**
     * attribute that will contain error message
     */
    private String message;
    /**
     * attribute that will contain the user email input by the user
     */
    private String email;
    /**
     * attribute that will contain the hash of password input by the user
     * We remember that for security reasons password are stored in the DB in way that 
     * it can't be restored for any reasons
     */
    private String hash_password;

    /** 
     * getter method for attribute hash_password 
     * @return hash_password
     */
    public String getHash_password() {
        return hash_password;
    }

    /** 
     * setter method for hash_password
     * @param hash_password 
     */
    public void setHash_password(String hash_password) {
        this.hash_password = hash_password;
    }

    /**
     * getter method for attribute password
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * setter method for attribute password
     * @param password 
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * getter method for attribute message
     * @return message
     */
    public String getMessage() {
        return message;
    }

    /**
     * setter methos for attribute message
     * @param message 
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * getter method for attribute email
     * @return email
     */
    public String getEmail() {
        return email;
    }

    /**
     * setter method for attribute email
     * @param email 
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Method that checks if the user exists inside the users database
     * and it creates a new session
     * @return String: it returns the page where we have to be readdressed
     */
    public String login(){
        //I check that the user exists inside the users database
        boolean result=UserEJB.login(email,password);

        if(result){   
            return "home";
        }else{
            return "login";
        }
    }

    /** 
     * MD5 algorithm for encrypting password. We provide a clear password as input
     * and as output we get a hashed function
     * @param message
     * @throws NoSuchAlgorithmException 
     */
    private void MD5(String password) throws UnsupportedEncodingException
    {
        try {
            MessageDigest m=MessageDigest.getInstance("MD5");
            m.update(password.getBytes(),password.length());
            System.out.println("MD5: "+new BigInteger(1,m.digest()).toString(16));

        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE,null,ex);
        }
    }

}

web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <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>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

当我运行它时,我收到此错误

Warning:   /index.xhtml @18,82 value="#{loginBean.email}": Target Unreachable,identifier 'loginBean' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml @18,identifier 'loginBean' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:126)
    at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:171)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045)
    at javax.faces.component.UIInput.validate(UIInput.java:975)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
    at org.primefaces.component.panel.Panel.processValidators(Panel.java:287)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
    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.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadioStrategy.run0(WorkerThreadioStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadioStrategy.access$100(WorkerThreadioStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadioStrategy$WorkerThreadRunnable.run(WorkerThreadioStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable,identifier 'loginBean' resolved to null
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
    at com.sun.el.parser.AstValue.getType(AstValue.java:86)
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 45 more

Severe:   javax.el.PropertyNotFoundException: /index.xhtml @18,identifier 'loginBean' resolved to null
    at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
    at com.sun.el.parser.AstValue.getType(AstValue.java:86)
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
    at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 45 more

解决方法

您正在为JSF managedbeans导入错误的包

替换这些:

import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;

import javax.faces.bean.ManagedBean;    
import javax.faces.bean.SessionScoped;

您导入的是JAVAEE CDI.您可能正在使用Tomcat,这就是他们没有工作的原因.

原文链接:https://www.f2er.com/html/231670.html

猜你在找的HTML相关文章