java.lang.ClassCastException:java.lang.Boolean不能在Struts的逻辑中强制转换为java.lang.String:等号

时间:2017-07-28 07:17:02

标签: java jsp struts-1

当我想访问我的jsp页面时出错。 我的bean:

public class BeChildren implements Serializable
{
...
 private String isFilledChildren;
....

    /**
     * @param isFilledChildrenthe isFilledChildrento set
     */
    public void setIsFilledChildren( String isFilledChildren)
    {
        this.isFilledChildren= isFilledChildren;
    }



    public String getIsFilledChildren( )
    {
        if ( getNom( ) != null )
        {
            return "true";
        } else
        {
            return "false";
        }
    }
...
}

错误:

28/07/17-09:13:10,670 ERROR org.apache.struts.taglib.tiles.InsertTag - ServletException in '/pages/sub/dir/detail/body.jsp': javax.servlet.jsp.JspException: Invalid argument looking up property: "bean.enfant.isFilledChildren" of bean: "sub/dir/detail"
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Invalid argument looking up property: "bean.enfant.isFilledChildren" of bean: "sub/dir/detail"

javax.servlet.jsp.JspException: Invalid argument looking up property: "bean.children.isFilledChildren" of bean: "sub/dir/detail"

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String

我的JSP:

https://pastebin.com/QmgtXBqA

...
<html:form action="/page/sub/dir/detail.do">
<html:hidden name="sub/dir/detail" property="modeCreation" styleId="modeCreation"/>
<html:hidden name="sub/dir/detail" property="bean.enfant.isFilledChildren"/>
....
<logic:equal name="sub/dir/detail" property="bean.enfant.isFilledChildren" value="true">
    .....
</logic:equal>
...
<script language="javascript" type="text/javascript">
    var f = document.forms[0];

    function init(){    
        var isFilledChildren = document.forms[0].elements["bean.enfant.isFilledChildren"];
        ....
        if (isFilledChildren!=null && "true"==isFilledChildren.value){
        ...
        }
    }
....

有什么问题?

3 个答案:

答案 0 :(得分:0)

String类型的属性应使用字符串值来避免ClassCastException

<logic:equal name="sub/dir/detail" property="bean.enfant.isFilledChildren" value="'true'">

答案 1 :(得分:0)

错误是因为您将布尔值传递给isFilledChildren属性作为参数

<logic:equal name="sub/dir/detail" property="bean.enfant.isFilledChildren" value="true">

在bean中,属性接受String值

答案 2 :(得分:0)

将isFilledChildren属性的类型更改为String将解决此问题。

如果没有,请尝试使用<logic:match /><logic:notMatch />(如果在此用例中可行)。请参阅下面的逻辑:匹配示例代码&#34;

<logic:match name="UserForm" property="favouriteFood" value="Pizza">