Struts 多模块应用

一、配置web.xml文档
添加模块moduleOne、moduleTwo
<!--mainModule-->
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<!--moduleOne-->
<init-param>
<param-name>config/moduleOne</param-name>
<param-value>/WEB-INF/moduleOne/struts-moduleOne.xml</param-value> </init-param>
<!--moduleTwo-->
<init-param>
<param-name>config/moduleTwo</param-name>
<param-value>/WEB-INF/moduleTwo/struts-moduleTwo.xml</param-value></init-param>

注:<param-name>格式必须这样写,<param-value>是指在WEB-INF目录下新建moduleOne目录再创建struts-moduleOne.xml,struts-moduleOne.xml格式与struts-config.xml相同。在此同时在WebRoot目录下新建moduleOne和moduleTwo的文件夹,用于区分模块和存放页面文件。
二、配置struts-config.xml
<struts-config>
<data-sources/>
<form-beanstype="org.apache.struts.webapp.CustomFormBean"/>
<global-exceptions/>
<global-forwards
type="org.apache.struts.webapp.CustomActionForward"/>
<action-mappings
type="org.apache.struts.webapp.CustomActionMapping">
<actionpath="/main"forward="/index.jsp"/>
</action-mappings>
<message-resourcesparameter="com.accp.struts.ApplicationResources"/> </struts-config>
注意:type这三个类是从何而来的呢??
答:自定义的所以在配置struts-config.xml之前我们应创建它们,当然每个类都必须extenx相应的父类,如下:
CustomFormBeanextenxFormBeanConfig
CustomActionForwardextenxActionForward
CustomActionMappingextenxActionMapping
这些类里面可以什么都不写,当然比较好点规范就是在里内添加一个属性,
如下:
privateStringexample="";
相应的get()set()

三、配置子模块
经过上面的配置基本已完成,那么我们现在来配置moduleOne子模块信息,添加action、actionFrom、jsp。
注意:action必须extendsDispatchAction,jsp页面应放在WebRoot目录下moduleOne
struts-moduleOne.xml如下:
<struts-config>
<data-sources/>
<form-beans>
<form-beanname="moduleOneForm"
type="com.accp.struts.form.ModuleOneForm">
</form-bean>
</form-beans>
<global-exceptions/>
<global-forwards>
<!--转发到moduleTwomodule指定哪个模块,全局转发-->
<forwardmodule="/moduleTwo"redirect="true"name="succeed"path="/displayUser.jsp"/>
</global-forwards>
<action-mappings>
<!--主模块index.jsplink导航-->
<actionpath="/reg"forward="/userRegist.jsp"/>
<actionpath="/regist"name="moduleOneForm"scope="session"parameter="user"
type="com.accp.struts.action.ModuleOneAction">
</action>
</action-mappings>
<message-resourcesparameter="com.accp.struts.ApplicationResources"/>
</struts-config>

index.jsp如下:
<html:linkmodule="/moduleOne"action="/reg.do">到moduleOne的用户注册</html:link>
注意:module属性,是指定某个模块,对应的就在某个模块配置<action/>

userRegist.jsp如下:
<html:formaction="/regist?user=addUser">
name:<html:textproperty="name"/><br/>
sex:<html:textproperty="sex"/><br/>
age:<html:textproperty="age"/><br/><br/>
<html:submitvalue="Submit"/><html:resetvalue="Reset"/>
</html:form>
注意:user是moduleOne.xml<actionparameter="user"....../>因为我们用到了DispatchAction,addUser是指action里的某个方法.

ModuleOneAction.java如下:
publicclassModuleOneActionextendsDispatchAction{
publicActionForwardaddUser(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){
ModuleOneFormmoduleOneForm=(ModuleOneForm)form;
System.out.println("name:"+moduleOneForm.getName());
System.out.println("age:"+moduleOneForm.getAge());
System.out.println("sex:"+moduleOneForm.getSex());
returnmapping.findForward("succeed");}}
displayUser.jsp
<body>
name:${moduleOneForm.name}<br/>
age:${moduleOneForm.age}<br/>
sex:${moduleOneForm.sex}<br/>
<html:linkaction="/main.do">回到主模块</html:link>
</body>
注意:displayUser.jsp位于moduleTwo目录,<html:link>没指定module所以默认从主模块的struts-config.xml寻找配对的<action>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的体育馆管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本体育馆管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此体育馆管理系统利用当下成熟完善的SpringBoot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线选择试题并完成答题,在线查看考核分数。管理员管理收货地址管理、购物车管理、场地管理、场地订单管理、字典管理、赛事管理、赛事收藏管理、赛事评价管理、赛事订单管理、商品管理、商品收藏管理、商品评价管理、商品订单管理、用户管理、管理员管理等功能。体育馆管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:体育馆管理系统;SpringBoot框架;Mysql;自动化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值