日期:2014-05-18 浏览次数:20634 次
public class LoginAction extends DispatchAction { //继承了DispatchAction
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.getSession().setAttribute("operation", "execute");
return mapping.findForward("error.jsp");
}
//login方法
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.getSession().setAttribute("operation", "login");
return mapping.findForward("error.jsp");
}
//register方法
public ActionForward register(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
request.getSession().setAttribute("operation", "register");
return mapping.findForward("error.jsp");
}
}
<action
path="/login"
type="com.mulan.struts.action.LoginAction"
scope="request"
input="/index.jsp"
validate="false"
parameter="operation" >
</action>
<form action="login.do?operation='login'" method="post">
用户名:<input type="text" name="temail"><br>
密码:<input type="password" name="tpass"><br>
<input type="submit" value="登录">
<a href="register.jsp">加入我们</a>
</form>
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (isCancelled(request)) {
ActionForward af = cancelled(mapping, form, request, response);