java.lang.ClassCastException: java.lang.Boolean 无法在 Struts 逻辑中转换为 java.lang.String:equal 标记

问题描述 投票:0回答:3

当我想访问我的 JSP 页面时出现错误。

我的豆子:

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){
        ...
        }
    }
....

出了什么问题?

java jsp struts-1
3个回答
0
投票

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

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

在你的bean中,属性接受字符串值


0
投票

String类型的属性应该使用字符串值以避免

ClassCastException

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

0
投票

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

如果没有,请尝试使用

<logic:match />
<logic:notMatch />
(如果在此用例中可行)。逻辑见下文:匹配示例代码”

<logic:match name="UserForm" property="favouriteFood" value="Pizza">
© www.soinside.com 2019 - 2024. All rights reserved.