struts2中set get执行顺序
package com.cy.action;
import java.util.Map;
import com.cy.domain.User;
import com.cy.operator.UserOperator;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
public class UserAction implements Action{
private User user;
@Override
public String execute() throws Exception {
System.out.println("execute");
return "success";
}
public String getAccount(){
System.out.println("getaccount");
UserOperator uo = new UserOperator();
boolean flag = uo.getAccount(user.getUname(), user.getUpass());
if(flag == true){
Integer uid = uo.getUidByName(user.getUname());
user.setUid(uid);
Map<String, Object> session = ActionContext.getContext().getSession();
session.put("user", user);
return "list";
}
else{
return "login";
}
}
public User getUser() {
System.out.println("get");
return user;
}
public void setUser(User user) {
System.out.println("set");
this.user = user;
}
}
如上,我从login.jsp转到这个action时。发现,控制台输出了get set get getaccount为什么先会执行get呢,按到底不是应该执行set吗?而且后一个get为什么执行,我在进入getaccount之前没用到get额,求大神们说说自己的看法。
<form action ="getAccount" >
<table border="3">
<tr>
<td>账号</td>
<td><input type = "text" , name = "user.uname" ></input></td>
</tr>
<tr>
<td>密码</td>
<td><input type = "password" , name = "user.upass" ></input></td>
</tr>
<tr>
<td colspan="2"><input type="reset" value = "重置"></input>
<input type ="submit" value = "确认"></input></td>
</table>
</form>
这是login里的代码。
谢谢大家。
------最佳解决方案--------------------set,getaccount,get..
------其他解决方案--------------------
我也是这么想的,调试的时候不是那样才觉得奇怪