最近在学习struts2关于action之间的跳转
后台代码:LoginAction.java
struts.xml配置:
方法一:redirectAction:
方法二:redirect:
后台代码:LoginAction.java
public class LoginAction extends ActionSupport{
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String login(){
Map session1=ActionContext.getContext().getSession();
session1.remove("name");
if(userName.length()<6){
return "failure";
}
System.out.println(userName+" ll");
if(password.length()>6){
Map session=ActionContext.getContext().getSession();
session.put("name", userName);
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("name", userName);}
return "success";
}
}
struts.xml配置:
方法一:redirectAction:
<action name="login" class="action.LoginAction">
<result name="success" type="redirectAction">
<param name="actionName">show</param>
<param name="userName">${userName}</param>
</result>
</action>
<action name="show" class="action.ShowAction">
<result name="success">/success.jsp</result>
</action>
方法二:redirect:
<action name="login" class="action.LoginAction">
<result name="success" type="redirect">/show.action?userName=${userName}
</result>
</action>
<action name="show" class="action.ShowAction">
<result name="success">/success.jsp</result>
</action>