1 分派action
首先创建struts的web项目,基本的action创建操作不在赘述,以下只描述DispatchAction的创建方法。
在创建action时,不继承action,而是继承他的子类,DispatchAction。
重写
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
方法,只是这里要把他重命名成你需要的函数,内容根据需要修改,如:
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
若这个类中还有其他的函数方法,则复制这个函数,修改函数名,作为区分:
public ActionForward logout(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
继续配置struts-config.xml:
在struts-config.xml中,找到上面action的标记位置,在参数中增加
parameter="flag"
flag作为标记名称,可以使用任意内容。
使用时,链接的位置是:
/strutslogin/login.do?flag=userLogin
/应用名/action.do?标记=类中选择的函数名
2 全局跳转
在struts-config.xml中添加内容:
在<action-mappings>之前添加:
<!-- 全局跳转forwards -->
<global-forwards>
<forward name="err" path="/WEB-INF/error.jsp" ></forward>
</global-forwards>
让系统内所有的action都能使用该跳转。