Struts的三种用法.也就是继承的三个类时分别如何写?

1.如果使用的class继承的是org.apache.struts.action.Action.
在struts-config.xml中该这样配
<struts-config>
  <data-sources />
  <form-beans />
  <global-exceptions />
  <global-forwards />
  <action-mappings >
   <action path="/test" type="net.tom.test.struts.TestAction" >
    <forward name="success" path="/test.jsp"></forward>
   </action>
 
 
   </action-mappings>
  <message-resources parameter="net.tom.test.struts.ApplicationResources" />
</struts-config>

2.如果使用的class继承的是org.apache.struts.actions.MappingDispatchAction
在struts-config.xml中该这样配

<struts-config>
 <!--form表单的注册 -->
 <form-beans>
  <form-bean name="userForm" type="net.tom.ecport.struts.forms.UserCheckForm"></form-bean>
  <form-bean name="userModifyForm" type="net.tom.ecport.struts.forms.UserModifyForm"></form-bean>
  <form-bean name="OrderForm" type="net.tom.ecport.struts.forms.OrderForm"></form-bean>
  
 </form-beans>
 
 <global-exceptions>
  <exception key="fail" type="/fail.jsp"></exception>
 </global-exceptions>
 
 
 <action-mappings>
  <action path="/index" type="net.tom.ecport.struts.actions.ProductMappingDispatchAction" parameter="index" >
   <forward name="success" path="/index.jsp"></forward>
  </action>
 
 
  <action path="/loginAction" type="net.tom.ecport.struts.actions.ProductMappingDispatchAction" parameter="loginAction"

name="userForm" validate="true" >
   <forward name="success" path="/registerSuccess.jsp"></forward>
  </action>
  
  </action-mappings>
 
 <message-resources parameter="net.tom.ecport.struts.action.ApplicationResources" key="other" />
 
</struts-config>
3.如果使用的class继承的org.apache.struts.actions.DispatchAction
:使用建议,同一个模块的处理方法建议用dispatchAction
DEMO:
 /**
  * 产生一个随机的账号.跳转到增加用户的界面
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return
  * @throws Exception
  */
 public ActionForward toAddAccount(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) throws Exception {
  log.info("========toAddAccount=======:获得随机生成的账号名开始");
  String account="";
  String str=Sequence.getSequence(0);
  account=str.substring(0,12);
  request.setAttribute("account", account);
  String success="addAccount";
  log.info("========toAddAccount=======:获得随机生成的账号名结束");
  return mapping.findForward(success);
 }
在struts-config.xml中该这样配
<struts-config>
 <action-mappings>
  <action path="/AccountAddAction" input="/accountList.jsp" name="OperatorEditActionForm"

type="com.uf.ufcrm.struts.action.AccountAddAction" parameter="method" validate="false" >
   <forward name="successbatch" path="/AccountAddAction.do?method=listAccount"

redirect="true"></forward>
   </action>
 </action-mappings> 
 <message-resources parameter="com.uf.ufcrm.struts.ApplicationResources"/>
</struts-config> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值