错误500:javax.servlet.ServletException:/Content.jsp(47,8)'#{bundle [' NAVIGATION_NAME']}:#{userInfo.name}'读取'名称'时出错在

时间:2016-12-28 12:22:39

标签: jsp jsf el

美好的一天! 我是这个论坛的新手,我也是Java开发的新手。我试图运行一个应用程序并遇到此错误。

  Error 500: javax.servlet.ServletException: /Content.jsp(47,8) '#{bundle['NAVIGATION_NAME']}: #{userInfo.name}' Error reading 'name' on type com.wbit.tel.client.jsf.infrastructure.UserInfo 

这是Content.jsp文件:

       

  <h:panelGrid styleClass="BackgroundNAV" columns="1">
    <h:form>

    <h:panelGrid styleClass="BackgroundHome" columns="1">
        <h:commandLink styleClass="NavigationLabelHome" action="Workplace">
             <h:outputText value="#{bundle['NAVIGATION_HOME']}" /> 
        </h:commandLink>
        <h:outputText rendered="#{arrayMetaInfo.init}" />       
    </h:panelGrid>


        <h:panelGrid styleClass="BackgroundBC" columns="1">
            <h:outputText styleClass="NavigationLabelBC" 
                            value="#{bundle['NAVIGATION_BUSINESS_CASES']}" />
            <h:commandLink styleClass="NavigationLink" action="BCCreate">
                <h:outputText value="#{bundle['NAVIGATION_CREATE_NEW']}" /> 
            </h:commandLink>

        </h:panelGrid>

    </h:form>
    <h:form target="_top">
        <h:panelGrid styleClass="BackgroundLO" columns="1">
            <h:outputText styleClass="NavigationLabelLO" 
                value="#{bundle['NAVIGATION_USER']}" />


            <h:outputText styleClass="NavigationLink" 
                value="#{bundle['NAVIGATION_NAME']}: #{userInfo.name}" />
            <h:outputText styleClass="NavigationLink" 
                value="#{bundle['NAVIGATION_EMAIL']}: #{userInfo.email}" />

        </h:panelGrid>
    </h:form>
    <h:form target="_top">
        <h:panelGrid styleClass="BackgroundLO" columns="1">
                <h:commandLink styleClass="NavigationLink" action="Logout">
                    <h:outputText value="#{bundle['NAVIGATION_LOGOUT']}" /> 
                </h:commandLink>
        </h:panelGrid>
    </h:form>
  </h:panelGrid>

这是userInfo.java文件:

公共类UserInfo实现Serializable {

private static final long serialVersionUID = 1L;

private java.util.Hashtable ownerInfo   = null;
private String userDisplayName          = null;
private String userFirstName            = null;
private String userLastName             = null;
private String userEmail                = null;
private String managerEmail             = null;
private java.util.Hashtable managerInfo = null;
private String currentRemoteUser        = null;
private boolean isLoggedIn              = false;


public UserInfo() {
    super();
    this.setLoggedIn(false);
}

public void userSetUp(String userID){
    try{
        if(userID == null) {
            userID = FacesUtils.getContext().getRemoteUser();
        }

        //we can't find a user?? I gues we are not logged in...
        if(userID == null || userID.trim().isEmpty()) {
            this.setLoggedIn(false);
        } else {
            BPResults results = BluePages.getPersonByCnum(userID);

            //user info
            ownerInfo               = results.getRow(0);

            String name             = (String) ownerInfo.get("NAME");
            userDisplayName         = BluePagesUtil.formatName(name);
            String names[]          = BluePagesUtil.separateName(name);
            userFirstName           = names[0];
            userLastName            = names[1];
            userEmail               = (String) ownerInfo.get("INTERNET");

            // This is to prevent certain processes that try to send mail to this email
            // from freaking out about a null value.
            userEmail = userEmail == null ? "" : userEmail; 
            //manager info
            BPResults management    = BluePages.getMgrChainOf(userID);
            managerInfo             = management.getRow(0);
            managerEmail            = (String)managerInfo.get("INTERNET");

            currentRemoteUser = userID;
        }
    } catch(Exception e) {
        //do nothing
        e.printStackTrace();
    }
}

/**
 * Return the locale for the user.
 */
public Locale getLocale() {
    return FacesUtils.getLocale();
}

/**
 * Return the name of current user.
 */
public String getName() {
    if (userDisplayName == null || currentRemoteUser == null 
            || !currentRemoteUser.equals(FacesUtils.getContext().getRemoteUser())) {
        userSetUp(null);
    }
    return userDisplayName;
}

public String getFirstName() {
    return userFirstName;
}

public void setFirstName(String userFirstName) {
    this.userFirstName = userFirstName;
}

public String getLastName() {
    return userLastName;
}

public void setLastName(String userLastName) {
    this.userLastName = userLastName;
}

/**
 * Return the email of current user.
 */
public String getEmail() {
    if (userEmail == null || currentRemoteUser == null 
            || !currentRemoteUser.equals(FacesUtils.getContext().getRemoteUser())) {
        userSetUp(null);
    }
    return userEmail;
}

public String getID() {
    return this.currentRemoteUser;
}

/**
 * Return the manager email of current user.
 */
@SuppressWarnings("unused")
private String getManagerEmail() {
    if (managerEmail == null || currentRemoteUser == null 
            || !currentRemoteUser.equals(FacesUtils.getContext().getRemoteUser())) {
        userSetUp(null);
    }
    return managerEmail;
}

/** 
 * Is user logged in? The user can exist but be not logged in. 
 * The status for this is set explicitly by the login form.
 */
public boolean isLoggedIn() {
    return isLoggedIn;
}

/** 
 * Is user logged in? The user can exist but be not logged in. 
 * The status for this is set explicitly by the login form.
 */
public void setLoggedIn(boolean isLoggedIn) {
    this.isLoggedIn = isLoggedIn;
    if(this.isLoggedIn)
        this.userSetUp(null);
}

@Override
public String toString() {
    return "Logged in? " + this.isLoggedIn + (!this.isLoggedIn ? "" : " - " + this.userEmail + " - " + this.userDisplayName); 
}

public void setEmail (String email){}
public void setID (String ID){}

}

重要说明:此代码适用于不同的项目/模块。我不明白为什么它不能在新的项目/模块中工作。是否需要我更改&#34; userInfo.name&#34;到另一个变量名?如果是这样,我应该在哪里更改它?

我真的需要帮助。我还在学习,希望有人能花时间帮助我。

谢谢!

2 个答案:

答案 0 :(得分:0)

您应该调试String getName()方法。有时,当被访问的方法抛出异常时,JSF只返回错误及其在页面上发生的行。

答案 1 :(得分:-1)

因此,当您从jsp引用 {userInfo.name} 时,它实际上是在您的userInfo对象上调用 userInfo.getName()方法。从我可以看到,UserInfo类中没有 name 字段,因为那里没有这样的方法。您可以使用 {userInfo.userDisplayName} 更改jsp,或在UserInfo类中添加getName()方法。

PS:与电子邮件字段相同,因为在jsp上还有 {userInfo.email} 参考。

相关问题