当我想访问我的 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:
...
<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){
...
}
}
....
出了什么问题?
错误是因为您将布尔值作为参数传递给 isFilledChildren 属性
<logic:equal name="sub/dir/detail" property="bean.enfant.isFilledChildren" value="true">
在你的bean中,属性接受字符串值
String类型的属性应该使用字符串值以避免
ClassCastException
。
<logic:equal name="sub/dir/detail" property="bean.enfant.isFilledChildren" value="'true'">
将 isFilledChildren 属性的类型更改为 String 可以解决此问题。
如果没有,请尝试使用
<logic:match />
和 <logic:notMatch />
(如果在此用例中可行)。逻辑见下文:匹配示例代码”
<logic:match name="UserForm" property="favouriteFood" value="Pizza">