概述
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>
最后
以上就是满意苗条为你收集整理的Struts的三种用法.也就是继承的三个类时分别如何写?的全部内容,希望文章能够帮你解决Struts的三种用法.也就是继承的三个类时分别如何写?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复