我正在使用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;
}