DispatchAction使用要点

1.action写法,注意:继承自dispatchaction;去掉execute()方法;add(),search()方法的定义完全照搬execute()。

public class PersonAction extends DispatchAction{
         public ActionForward add(ActionMapping mapping,
                            ActionForm form,
                            HttpServletRequest request,
                            HttpServletResponse response)
          throws Exception {
          ...
          ...
          }
         
         public ActionForward search(ActionMapping mapping,
                            ActionForm form,
                            HttpServletRequest request,
                            HttpServletResponse response)
          throws Exception {
          ...
          ...
          }
}
2 struts-config.xml的配置,注意在<action>的配置中加上parameter=method属性,其他属性根据需要配置
<action path="/person"
    parameter="method"
  scope="request"
  type="com.***.PersonAction"  
  validate="false">
3请求中的路径,通过method=add来定位到action中的add()方法
<html:form action="/PersonAction.do?method=add">

你可能感兴趣的:(xml,struts)