DispatchAction 到底怎么使用的啊
我按照网上说的 首先是类继承DispatchAction ,然后写了些测试代码 代码如下:
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);
if (af != null) {
return af;
}
}
// Get the parameter. This could be overridden in subclasses.
String parameter = getParameter(mapping, form, request, response);
// Get the method's name. This could be overridden in subclasses.
String name =
getMethodName(mapping, form, request, response, parameter);
// Prevent recursive calls
if ("execute".equals(name)
[解决办法]
"perform".equals(name)) {
String message =
messages.getMessage("dispatch.recursive", mapping.getPath());
log.error(message);
throw new ServletException(message);
}
// Invoke the named method, and return the result
return dispatchMethod(mapping, form, request, response, name);
}