2017-07-28 74 views
1

當我想訪問我的jsp頁面時出現錯誤。 我的豆:java.lang.ClassCastException:java.lang.Boolean不能在Struts邏輯中強制轉換爲java.lang.String:等於標記

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

出了什麼問題?

+1

@Mercer你可以理解我們可以檢查所有代碼你可以只貼上的你PROGRAMM說,有問題的代碼,我不認爲這是!難以理解 –

+0

你看到類拋出異常嗎?似乎是你的JSP期望的數據類型布爾值,而不是字符串 –

+0

@MichaelMeyer我看到,但我沒有布爾數據類型 – Mercer

回答

0

字符串類型的屬性應使用字符串值來避免ClassCastException

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

的錯誤是ecause你作爲參數

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

傳遞布爾值isFilledChildren財產在你的bean的屬性接受字符串值

+0

pass boolean valu e以isFilledChildren屬性作爲參數?爲什麼具有布爾值的屬性應接受字符串或如何將布爾值轉換爲字符串? –

+0

嘗試使用value =「'true'」? – MaVRoSCy

+0

對,字符串值應該在引號中。 –

0

更改爲isFilledChildren屬性字符串類型將解決此。

如果沒有,請使用<logic:match /><logic:notMatch />(如果在此用例中可行)。請參見下面的邏輯:比賽示例代碼」

<logic:match name="UserForm" property="favouriteFood" value="Pizza"> 
相關問題