日期:2014-05-20  浏览次数:20877 次

struts2 action与action之间传值的问题~~
我写了一个用户登陆的类~ 如果是管理员就登陆到管理页面,如果是普通用户就跳转到另一个action并用上一个action的参数查询出数据,但是问题就出在action传值上,我参考了很多网上的资料 并一一试了之后 还是得不到上一个action的参数。请大家帮忙看看我的代码. 我写了set/get方法 也用param传了参数, 也试了在session里面取 但是都没有成功,请问我的问题出在那里呢???

struts.xml

<action name="login" class="action.LoginAction">
<result name="input" type="redirectAction" >
<param name="actionName">guerinfo.action</param> 
  <param name="namespace">/</param> 
  <param name="school_id">${school_id}</param>
  <param name="password">${password}</param>
</result>
<result name="success">/main.jsp</result>
<result name="error">/error.jsp</result>
</action>
<action name="guerinfo" class="action.GuserInfoAction">
<result name="success">/guser.jsp</result>
<result name="error">/error.jsp</result>
</action>
LoginAction

public class LoginAction extends ActionSupport{

private User user = new User();
private String school_id;
private String password;

public String execute() throws Exception {

school_id=user.getSchool_id();
password=user.getPassword();

if(UserDao.CheckLogin(user.getSchool_id(), user.getPassword()).equals("admin")){
ActionContext.getContext().getSession().put("school_id",user.getSchool_id());
ActionContext.getContext().getSession().put("password",user.getPassword());
return SUCCESS;
}else if(UserDao.CheckLogin(user.getSchool_id(), user.getPassword()).equals("user")){
ActionContext.getContext().getSession().put("school_id",user.getSchool_id());
ActionContext.getContext().getSession().put("password",user.getPassword());
return INPUT;
}else{

return ERROR;
}
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String getSchool_id() {
return school_id;
}

public void setSchool_id(String school_id) {
this.school_id = school_id;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}


GuserInfoAction

public class GuserInfoAction extends ActionSupport{

private List<Employee> guserlist = null;
private User user = new User();
private String school_id;
private String password;

public String execute() {
try{
school_id=user.getSchool_id();
password=user.getPassword();

System.out.println(school_id+password);

guserlist = GuserDao.getGuserList(user.getSchool_id(), user.getPassword());
Map map = ActionContext.getContext().getSession();
this.setGuserlist(guserlist);
map.put("guserlist", guserlist);

} catch (SQLException e) {
guserlist = null;
e.printStackTrace();
}
return SUCCESS;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public List<Employee> getGuserlist() {
return guserlist;
}

public void setGuserlist(List<Employee> guserlist) {
this.guserlist = guserlist;
}

public String getSchool_id() {
return school_id;
}

public void setSchool_id(String school_id) {
this.school_id = school_id;