<set> 中的无效属性:JSP 的新 ArrayList 中的“null”
Posted
技术标签:
【中文标题】<set> 中的无效属性:JSP 的新 ArrayList 中的“null”【英文标题】:Invalid property in <set>: "null" in new ArrayList at JSP 【发布时间】:2017-12-16 15:46:56 【问题描述】:我有一组对象。我需要对其进行迭代并添加我在 JSP 页面上创建的新 ArrayList。但是我有一个错误
javax.servlet.jsp.JspTagException:
中的无效属性:“null”
这是我的代码
<jsp:useBean id="idList" class="java.util.ArrayList"/>
<c:forEach items="$car.tape.idSet" var="item">
<c:set target="$idList" value="$item.id"/>
</c:forEach>
<aui:input class="form-check" checked="$idList.contains(1)?'true':''" inlineLabel="right"
name="name1"
type="checkbox" value="1"
label="Name1"/>
<aui:input class="form-check" checked="$idList.contains(2)?'true':''" inlineLabel="right"
name="name2" type="checkbox" value="2"
label="name2"/>
【问题讨论】:
【参考方案1】:你得到了错误
“avax.servlet.jsp.JspTagException:无效属性:“null”“
因为你没有在中指定任何属性属性
<c:set /> something like
<c:set target="$myclass" property="attrib" value="somevalue"/>
但在您的情况下,ArrayList 是 bean,您想在其中设置一些值。请尝试使用以下示例代码。 包 com.example
public class ArrayListBean
private List<Object> list = new ArrayList<Object>();
public void setList(Object object)
list.add(object);
public List<Object> getList()
return list;
之后只需修改您的代码,如下所示:
<jsp:useBean id="idList" class="com.example.ArrayListBean"/>
<c:forEach items="$car.tape.idSet" var="item">
<c:set target="$idList" property="list" value="$item.id" />
</c:forEach>
<aui:input class="form-check" checked="$idList.contains(1)?'true':''" inlineLabel="right" name="name1" type="checkbox" value="1 label="Name1"/>
<aui:input class="form-check" checked="$idList.contains(2)?'true':''" inlineLabel="right" name="name2" type="checkbox" value="2" label="name2"/>
或
<jsp:useBean id="idList" class="com.example.ArrayListBean"/>
<c:forEach items="$car.tape.idSet" var="item">
<jsp:setProperty name="idList" property="list" value="$item.id" />
</c:forEach>
<aui:input class="form-check" checked="$idList.contains(1)?'true':''" inlineLabel="right" name="name1" type="checkbox" value="1 label="Name1"/>
<aui:input class="form-check" checked="$idList.contains(2)?'true':''" inlineLabel="right" name="name2" type="checkbox" value="2" label="name2"/>
<jsp:setProperty>, This works basically the same way, only the name must refer the bean name, not the bean itself.
<jsp:useBean id="bean" class="com.example.Bean" />
<jsp:setProperty name="bean" property="someProperty" value="newvalue" />
对我来说很好用。
【讨论】:
以上是关于<set> 中的无效属性:JSP 的新 ArrayList 中的“null”的主要内容,如果未能解决你的问题,请参考以下文章