<script>
function regist()
{
targetForm = document.forms[0];
targetForm.action = "login!regist";
}
</script>
struts.xml
...
<package name="lee" extends="struts-default">
<!-- 配置login Action,处理类为LoginRegistAction
默认使用execute方法处理请求-->
<action name="zcw" class="com.zcw.LoginRegistAction">
<!-- 定义逻辑视图和物理视图之间的映射关系 -->
<result name="input">/login.jsp</result>
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
<!-- 配置regist Action,处理类为LoginRegistAction
指定使用regist方法处理请求-->
<action name="regist" class="lee.LoginRegistAction" method="regist">
<!-- 定义逻辑视图和物理视图之间的映射关系 -->
<result name="input">/login.jsp</result>
<result name="error">/error.jsp</result>
<result name="success">/welcome.jsp</result>
</action>
</package>
...
LoingRegistAction.java
...
@Override
public String execute() throws Exception {
if(this.getUsername().equals("zcwfeng") && this.getPassword().equals("zcwfeng")){
ActionContext.getContext().getSession().put("user", this.getUsername());
setTip("欢迎"+this.getUsername()+",您成功登陆");
return SUCCESS;
}else{
return ERROR;
}
}
public String regist() throws Exception{
ActionContext.getContext().getSession().put("user", this.getUsername());
this.setTip("恭喜您"+this.getUsername()+",成功注册");
return SUCCESS;
}
...