查阅了资料 说 <s:textfield/>标签的name和value是绑定只要设对名字就可以取得value值
action.java
... public String updateUI() {
ActionContext.getContext().put("department", departmentService.find(dep_id));
return "add";
}...
add.jsp
<s:form action="manage_saveorupdate"
namespace="/department" method="get">
<s:token></s:token>
<s:hidden name="#department.dep_id" id="department.dep_id" />
部门名称:<s:textfield name="#department.dep_name" id="department.dep_name"/>
<br />
部门简称:<s:textfield name="#department.dep_shortname" id="department.dep_shortname"/>
<br />
<input type="submit" value="保存" />
</s:form>
1、我这样设置好后 可以updateUI.do 页面可以得到对应的部门对象,但是提交后又没法按name去取值。
求大虾 这个怎么取department对象
2、有什么其他好的方法 做修改提交页面?
Struts Java 对象 HTML 标签
------解决方案--------------------
在方法外面定义一个department对象,生成get、set方法,然后在updateUI()里将查询出来的数据封闭在department对象里面,在jsp页面通过对象department去取值.提交的时候提交department对象
------解决方案--------------------
private Department department;
public String updateUI() {
if (department == null) {
department = new Department();
}
department = departmentService.find(dep_id);
return "add";
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
<s:textfield id="dep_name" name="department.dep_name" ></s:textfield>
------解决方案--------------------
#是多余的,id=“”去掉