Java ognl.OgnlException:getProperty的源为null(null,“0”错误
我可以显示值并编辑它们,但当我提交表单时,它会遇到以下错误 JavaJava ognl.OgnlException:getProperty的源为null(null,“0”错误,java,jsp,struts2,iterator,ognl,Java,Jsp,Struts2,Iterator,Ognl,我可以显示值并编辑它们,但当我提交表单时,它会遇到以下错误 Java public Class Baskets { private Basket basket; ... public String edit(){ System.err.println("item>>>" + this.basket.getItems().get(0).getProduct().getPrice()); ... } getter and setters }
public Class Baskets {
private Basket basket;
...
public String edit(){
System.err.println("item>>>" + this.basket.getItems().get(0).getProduct().getPrice());
...
}
getter and setters
}
JSP
<form name="edit" method="POST" action="edit">
<table border="4">
<thead><td>Product</td><td>Price 2</td><td>User</td><td>Time</td></thead>
<tbody>
<s:iterator value="basket.items" var="item" status="cur">
<tr>
<s:textfield type="hidden" id="item[%{#cur.index}].id" name="item[%{#cur.index}].id" value="%{id}" theme="simple"/>
<td>
Price : <s:textfield id="item[%{#cur.index}].product.price" name="item[%{#cur.index}].product.price" value="%{prodcut.price}" theme="simple"/>
<br/>
Name: <s:label value="%{product.name}" theme="simple"/>
</td>
<td>
<s:textfield name="item[%{#cur.index}].product.price2"
id="item[%{#cur.index}].product.price2"
value="%{product.price2}" theme="simple"/>
</td>
<td><s:label value="%{name}" theme="simple"/> </td>
<td><s:label value="%{time}" theme="simple"/> </td>
</tr>
</s:iterator>
</tbody>
</table>
<input id="edit" type="submit" name="action" value="Edit"/>
</form>
浏览器错误
java.lang.NullPointerException
com.myproject.controller.Baskets.edit(Baskets.java:100)
第100行如下所示
System.err.println("item>>>" + this.basket.getItems().get(0).getProduct().getPrice());
HTML
<form name="edit" method="POST" action="edit">
<table border="4">
<thead><td>Product</td><td>Price 2</td><td>User</td><td>Time</td></thead>
<tbody>
<tr>
<input type="hidden" name="item[0].id" value="16" id="item[0].id"/>
<td>Price : <input type="text" name="item[0].product.price"
value="55" id="item[0].product.price"/>
<br/>
Name: <label id="">Product 1</label> </td>
<td><input type="text" name="item[0].product.price2" value="1000"
id="item[0].product.price2"/></td>
<td><label id="">User1</label> </td>
<td><label id="">9:31:03 AM</label> </td>
</tr>
<tr>
<input type="hidden" name="item[1].id" value="17" id="item[1].id"/>
<td>Price : <input type="text" name="item[1].product.price"
value="60" id="item[1].product.price"/>
<br/>
Name: <label id="">Product 2</label> </td>
<td><input type="text" name="item[1].product.price2" value="1000"
id="item[1].product.price2"/></td>
<td><label id="">User1</label> </td>
<td><label id="">11:25:55 AM</label> </td>
</tr>
</tbody>
</table>
<label id="balance"></label>
<input id="edit" type="submit" name="action" value="Edit"/>
</form>
ProductPrice 2用户时间
价格:
名称:产品1
用户1
上午9:31:03
价格:
名称:产品2
用户1
上午11:25:55
“item[{#cursor.index}].product.price“
缺少%@coding\u idiot如果我这样说,生成的HTML将是%item[0]。product.price并且它遇到了相同的错误“item[{#cursor.index}]。product.price“
缺少%@coding\u idiot如果我这样说,生成的HTML将是%item[0].product.price,它遇到了相同的错误当我添加它时,生成的HTML是,错误是ognl.OgnlException:source对于getProperty是null(null,“0”)生成的HTML将是
或是
?您是否尝试过进行更改并提交表单?你还会犯同样的错误吗?如果是,那么很确定某个字段的名称是错误的,请发布完整的表单和完整的html。this.basket。
-第100行-basket是什么?basket是购物车对象,每个购物车有不同的项目,每个项目中有一个产品以及用户的时间和名称,每个产品都有两个价格。那么字段的名称是错误的,我们需要将名称更改为basket.item[%{cursor.index}].id
当我添加该名称时,生成的HTML是,错误是ognl.OgnlException:source是null for getProperty(null,“0”)生成的HTML将是
还是是
?您是否尝试过进行更改并提交表单?你还会犯同样的错误吗?如果是,那么很确定某个字段的名称是错误的,请发布完整的表单和完整的html。this.basket。
-第100行-basket是什么?basket是购物车对象,每个购物车有不同的项目,每个项目中有一个产品以及用户的时间和名称,每个产品都有两个价格。那么字段的名称是错误的,我们需要将名称更改为basket.item[%{cursor.index}].id
<form name="edit" method="POST" action="edit">
<table border="4">
<thead><td>Product</td><td>Price 2</td><td>User</td><td>Time</td></thead>
<tbody>
<tr>
<input type="hidden" name="item[0].id" value="16" id="item[0].id"/>
<td>Price : <input type="text" name="item[0].product.price"
value="55" id="item[0].product.price"/>
<br/>
Name: <label id="">Product 1</label> </td>
<td><input type="text" name="item[0].product.price2" value="1000"
id="item[0].product.price2"/></td>
<td><label id="">User1</label> </td>
<td><label id="">9:31:03 AM</label> </td>
</tr>
<tr>
<input type="hidden" name="item[1].id" value="17" id="item[1].id"/>
<td>Price : <input type="text" name="item[1].product.price"
value="60" id="item[1].product.price"/>
<br/>
Name: <label id="">Product 2</label> </td>
<td><input type="text" name="item[1].product.price2" value="1000"
id="item[1].product.price2"/></td>
<td><label id="">User1</label> </td>
<td><label id="">11:25:55 AM</label> </td>
</tr>
</tbody>
</table>
<label id="balance"></label>
<input id="edit" type="submit" name="action" value="Edit"/>
</form>
<s:textfield id="item[ {#cursor.index}].product.price"
name="item[%{#cursor.index}].product.price"
value="%{product.price}" />
<s:textfield id="basket.item[%{#cursor.index}].product.price"
name="basket.item[%{#cursor.index}].product.price"
value="%{product.price}" />