【发布时间】:2011-03-09 18:38:18
【问题描述】:
我正在使用jsp和struts2,我有以下场景:
<s:form>
<s:hidden name="empId" value="123"/>
<s:textfield name="employee.name"/>
<s:submit action="save"/>
</s:form>
当这个表单被提交时,OGNL 表达式employee.name(相当于getEmployee().setName())在“save”方法之前被执行。而且,“empId”的值在 getEmployee() 方法中不可用。 “empId”的值仅在“save”方法中可用。是否可以在 getEmployee() 中获取“empId”的值?
以下是我的 Action 类中的代码:
public String save() {
//empId is available here
return SUCCESS;
}
public Employee getEmployee(){
if (employee == null){
//empId is not available here
employee = employeeService.get(empId);
}
return employee;
}
【问题讨论】:
-
请提供相关的struts2 xml/annotations,一般来说我们更容易阅读,然后是阅读英文版。
-
四元数,谢谢回复。我已将问题编辑为更清楚。请检查您是否能够理解场景。