這是spring mvc portlet的一部分,我們試圖從控制器的視圖圖層中檢索模型屬性,但它顯示爲空。 我們嘗試使用modelAttribute
以及commandName
與bean名稱和表單輸入字段以及與bean屬性相對應的路徑名稱。無法從spring中查看模型屬性mvc portlet
查看JSP
<form:form id="empForm" modelAttribute="empBean" action="${createEmpURL}" method="POST" class="form-horizontal">
<form:hidden path="empId"></form:hidden>
<div class="control-group">
<label class="control-label" for="empName">Employee Name</label>
<div class="controls">
<form:input type="text" id="empName" path="empName"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="grade">Grade</label>
<div class="controls">
<form:input type="text" id="grade" path="grade"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<input id="validateNewEmployeeButton" class="btn btn-primary" type="submit" value="Create"/>
</div>
</div>
Controller類
@ActionMapping
public void createEmp(@ModelAttribute("empBean") Employee emp, BindingResult bindingResult,ActionRequest req,ActionResponse res)
{
System.out.println("------------->"+emp);
}
乙EAN類
public class Employee implements Comparable<Employee>,Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long empId;
private String empName;
private String grade;
public long getEmpId() {
return empId;
}
public Employee() {
super();
// TODO Auto-generated constructor stub
}
public void setEmpId(long empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
@Override
public int compareTo(Employee o) {
return (int) (this.getEmpId() - o.getEmpId());
}
}
Update
使用這個網址行動網址:<portlet:actionURL var="createEmpURL" escapeXml="false"> </portlet:actionURL>
上,這可能是缺少可能將是有益的任何線索,請爲需要的任何進一步的細節發表評論。
你得到任何錯誤?什麼是你映射的網址? –
@shantaram_t每sese沒有錯誤。我將表單映射到一個動作URL.Will更新問題 –