我遇到了使用构造从我的JSP通过POST向后端发送数据的问题:
<form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
在sumbit之后我的Jboss(版本5)显示:
HTTP Status 400 - description: The request sent by the client was syntactically incorrect ().
我不知道如何查看已发送的请求。当我在下面使用构造时,一切正常,但我不想只从对象绑定一个值,而是整个对象:
<form:radiobuttons path="pvClCategory.clcaCategory" items="${categoryList}" itemValue="clcaCategory" itemLabel="clcaCategory"/>
所以,第一个表单构造(绑定整个对象)会导致我遇到问题。表单已正确初始化,这意味着正确显示了无线电选项,并在jsp站点上选择了正确的值。但是当我想提交表单时出现问题,我收到错误(客户端发送的HTTP状态400请求在语法上是不正确的)。知道为什么吗?我做错了什么?
我有一个实体类Violation,其字段名为pCClCategory类型的ClCategory
@Entity
@Table(name="PV_VIOLATIONS")
public class Violation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="VIOL_ID")
private Long id;
@ManyToOne
@JoinColumn(name="VIOL_CLCA_ID")
private ClCategory pvClCategory;
/* others fields and getters/setters */
}
将其绑定到Violation.pvClCategory字段所需的我的ClCategory实体类:
@Entity
@Table(name="PV_CL_CATEGORIES")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class ClCategory implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="CLCA_ID")
private long clcaId;
@Column(name="CLCA_CATEGORY")
private String clcaCategory;
@OneToMany(mappedBy="pvClCategory")
private List<Violation> pvViolations;
public ClCategory() {
}
public long getClcaId() {
return this.clcaId;
}
public void setClcaId(long clcaId) {
this.clcaId = clcaId;
}
public String getClcaCategory() {
return this.clcaCategory;
}
public void setClcaCategory(String clcaCategory) {
this.clcaCategory = clcaCategory;
}
public List<Violation> getPvViolations() {
return this.pvViolations;
}
public void setPvViolations(List<Violation> pvViolations) {
this.pvViolations = pvViolations;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (clcaId ^ (clcaId >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ClCategory other = (ClCategory) obj;
if (clcaId != other.clcaId)
return false;
return true;
}
}
此Violation类在commandName属性中以我的形式使用,如下所示(文件名:v.jsp):
<form:form action="../update" method="post" commandName="violation">
<form:radiobuttons path="pvClCategory" items="${categoryList}" itemLabel="clcaCategory"/>
<!-- other fields -->
<button type="submit" value="Apply Changes" class="button-default" >Apply</button>
</form:form>
我的控制器:
@Controller
@RequestMapping("/viol")
public class ViolationController {
@RequestMapping("edit/{violationId}")
public String edit(@PathVariable("violationId") long id, Map<String, Object> map) {
Violation violation = violationService.getViolation(id);
map.put("violation",violation);
map.put("categoryList", adminService.listCategories());
return "v";
}
}
据我所知,在构造形式:radiobuttons path =&#34;&#34; items =&#34;&#34; 路径是数据绑定的属性,因此项目中已传递列表的整个对象应绑定到它。我放入了我的类别列表,这些类别是ClCategory类型的对象。出现提交错误后。
当我使用形式时:radiobuttons path =&#34; pvClCategory.clcaCategory&#34;项=&#34; $ {所属分类}&#34;项目值=&#34; clcaCategory&#34; itemLabel =&#34; clcaCategory&#34; 只绑定项目中对象的String值(在两种情况下都使用类型为ClCategory的对象列表)然后表单被正确地提交但我不想绑定只有一个对象的值而是整个对象。你能帮我解决一下我做错了吗?