【问题标题】:HTTP Status 500 - Unable to compile class for JSP, The method is undefinedHTTP 状态 500 - 无法为 JSP 编译类,方法未定义
【发布时间】:2015-01-07 07:30:23
【问题描述】:

我有一个使用 Netbeans 7.4/Jdk7/Tomcat7 的项目。

项目在前端使用Spring框架,在后端使用soap WCF服务。我声明,服务中的一种方法存在问题。我可以在 spring 中得到这个方法而没有任何编译错误,但是当我尝试运行项目时它会抛出异常:

org.apache.jasper.JasperException:无法为 JSP 编译类:
在 jsp 文件中的第 30 行发生错误:/WEB-INF/jsp/include/page_header.jsp
方法 isIsPosUser() 未为 UserInfo 类型定义

我的 UserInfo 类:

[Serializable, XmlRoot("user_info")]
[DataContract(Name = "user_info", Namespace = "urn:...")]
public class UserInfo
{
    private String _FullName;
    private String _EMail;
    private bool _IsPosUser;

    public UserInfo(string pFullName, 
                    string pEmail)
    {
        FullName = pFullName;
        EMail = pEmail;
    }

    public UserInfo()
    {
        //dummy
    }

    [XmlElement(ElementName = "full_name")]
    [DataMember(Name = "full_name")]
    public string FullName
    {
        get { return _FullName; }
        set { _FullName = value; }
    }

    [XmlElement(ElementName = "e_mail")]
    [DataMember(Name = "e_mail")]
    public string EMail
    {
        get { return _EMail; }
        set { _EMail = value; }
    }

    [XmlElement(ElementName = "IsPosUser")]
    [DataMember(Name = "IsPosUser")]
    public bool IsPosUser
    {
        get { return _IsPosUser; }
        set { _IsPosUser = value; }
    }

    public override string ToString()
    {
        return string.Format("FullName: {0}, EMail: {1}, IsPosUser: {2}", FullName, EMail, IsPosUser);
    }
}

spring app中导入wsdl生成的源码:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserInfo", propOrder = {
"fullName",
"eMail",
"isPosUser"
})
public class UserInfo {

@XmlElement(name = "full_name")
protected String fullName;
@XmlElement(name = "e_mail")
protected String eMail;
@XmlElement(name = "IsPosUser")
protected boolean isPosUser;


/**
 * Gets the value of the fullName property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getFullName() {
    return fullName;
}

/**
 * Sets the value of the fullName property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setFullName(String value) {
    this.fullName = value;
}

/**
 * Gets the value of the eMail property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getEMail() {
    return eMail;
}

/**
 * Sets the value of the eMail property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setEMail(String value) {
    this.eMail = value;
}

/**
 * Gets the value of the isPosUser property.
 * 
 */
public boolean isIsPosUser() {
    return isPosUser;
}

/**
 * Sets the value of the isPosUser property.
 * 
 */
public void setIsPosUser(boolean value) {
    this.isPosUser = value;
}

}

我尝试在身份验证后在 jsp 文件中获取此值:

<%
    SoapUsernamePasswordAuthenticationToken retVal = (SoapUsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
    UserInfo userInfo = retVal.getUserInfo();
    boolean isPosUser = userInfo.isIsPosUser();
%>

这里抛出异常。如果我从我的 spring 应用程序中删除这个方法调用,一切正常。问题出在 userInfo.isIsPosUser();但无法弄清楚是什么原因。

提前致谢!

【问题讨论】:

    标签: java spring wcf tomcat jakarta-ee


    【解决方案1】:

    你错过了在脚本中输入 isPosUser()

    boolean isPosUser = userInfo.IsPosUser();
    

    代替:

    boolean isPosUser = userInfo.isIsPosUser();
    

    【讨论】:

    • 如果我尝试编写 userInfo.isPosUser() 而不是 userInfo.isIsPosUser(),则会出现编译错误。因为自动生成文件中的方法是: /** * 获取isPosUser属性的值。 * */ public boolean isIsPosUser() { return isPosUser; }
    • userInfo.IsPosUser();第一个大写字母
    • 找不到符号符号:方法 IsPosUser() 位置:UserInfo 类型的变量 userInfo
    • 为什么会有这个getter这样命名 /** * 获取isPosUser属性的值。 * */ public boolean isIsPosUser() { return isPosUser; }
    • 公共布尔 isIsPosUser();也改变: public boolean isPosUser() ;
    猜你喜欢
    • 1970-01-01
    • 2014-05-27
    • 2017-03-24
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    • 2013-11-04
    • 2014-10-01
    • 2017-04-11
    相关资源
    最近更新 更多