在Struts框架下大型Web应用程序的开发 广东精鹰软件工作室(刘正仁)

本文介绍了Struts1.1多模块应用开发,包括多模块与单模块应用程序的区别。以CliffordWeb为例,阐述了多模块应用程序的目录结构,给出了web.xml及各模块Struts配置文件样例,还说明了各配置文件作用,最后介绍了模块间Action跳转的两种方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(应用程序多模块团队的开发)

 

 

 

 

struts1.1允许将单个Struts应用划分成几个模块,每个模块有自己的Struts配置文件,JSP页面,Action等等。这个新特性是为了解决大中型的开发队伍抱怨最多的一个问题,即为了更好的支持并行开发允许多个配置文件而不是单个配置文件。

 

 

 

下面就近我在开发知识库时顺便做的一个样例说一下自己的体会,从应用程序的结构,配置,模块之间的跳转三个方面做些说明,在说明之前,解释我下面所用到的两个术语避免产生岐义。

 

 

 

多模块应用程序:在本文中是指开发Struts应用程序时,不同的应用模块独立地配置自己的struts-config.xml文件。

 

 

 

单模块应用程序:在本文中是指开发Struts应用程序时,不同的应用模块只有一个struts-config.xml文件。(实际上也是多个模块的)

 

 

 

 

 

 

 

我的Struts应用程序名为CliffordWeb,下面有两个模块:样例模块(Exsample)和知识库模块(Repository),样例模块是为了说明问题而添加的。

 

 

 

 

 

 

 

一、在多模块应用程序开发时的应用程序目录结构。

 

 

 

多模块应用程序与单模块应用程序目录结构基本上是一样的。所以如果我们要将现有的单模块应用程序转化为多模块应用程时,目录结构几乎不需要做任何修改。(最好每个模块的目录都是一级目录)

 

 

 

CliffordWeb

 

 

 

……. WEB-INF

 

 

 

……. ……. …….

 

 

 

……. ……. struts-config.xml

 

 

 

……. ……. struts-config-Repository.xml

 

 

 

……. ……. struts-config-Exsample.xml

 

 

 

……. ……. …….

 

 

 

……Exsample(应用模块)

 

 

 

……. …….Jsp

 

 

 

……Repository(应用模块)

 

 

 

……. ……. Jsp

 

 

 

…….Images

 

 

 

…….JS

 

 

 

…….Include

 

 

 

…….

 

 

 

从上面的目录结构我们可以看到它基本上和我们目前开发的结构是一样的。只是在WEB-INF目录中多了两个Struts配置文件(struts-config-Repository.xmlstruts-config- Exsample.xml)。这两个配置文件分别对应知识库和登录两个模块。

 

 

 

 

 

 

 

二、相关的配置文件及作用

 

 

 

在多模块应用程序开发时,我们需要配置Web.xml及各个应用模块的Struts配置文件,下面我给出各个配置文件的样例。(注意蓝色的部分)

 

 

 

1、   web.xml

 

 

 

 

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

 

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

 

 

 

<web-app>

 

 

 

  <display-name>CliffordWeb</display-name>

 

 

 

  <filter>

 

 

 

    <filter-name>SetCharacterEncoding</filter-name>

 

 

 

    <filter-class>com.jwz.common.filters.SetCharacterEncodingFilter</filter-class>

 

 

 

    <init-param>

 

 

 

      <param-name>encoding</param-name>

 

 

 

      <param-value>GBK</param-value>

 

 

 

    </init-param>

 

 

 

  </filter>

 

 

 

  <filter-mapping>

 

 

 

    <filter-name>SetCharacterEncoding</filter-name>

 

 

 

    <url-pattern>/*</url-pattern>

 

 

 

  </filter-mapping>

 

 

 

  <servlet>

 

 

 

    <servlet-name>RepositoryCategoryService</servlet-name>

 

 

 

    <servlet-class>com.clifford.repository.servlet.CategoryService</servlet-class>

 

 

 

  </servlet>

 

 

 

  <servlet>

 

 

 

    <servlet-name>action</servlet-name>

 

 

 

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

 

 

 

    <init-param>

 

 

 

      <param-name>config </param-name>

 

 

 

      <param-value>/WEB-INF/struts-config.xml</param-value>

 

 

 

</init-param>

 

 

 

    <init-param>

 

 

 

      <param-name>config/Repository</param-name>

 

 

 

      <param-value>/WEB-INF/struts-config-Repository.xml</param-value>

 

 

 

</init-param>

 

 

 

    <init-param>

 

 

 

      <param-name>config/Logon</param-name>

 

 

 

      <param-value>/WEB-INF/struts-config-Logon.xml</param-value>

 

 

 

</init-param>

 

 

 

    <init-param>

 

 

 

      <param-name>debug</param-name>

 

 

 

      <param-value>2</param-value>

 

 

 

    </init-param>

 

 

 

    <load-on-startup>2</load-on-startup>

 

 

 

  </servlet>

 

 

 

  <servlet>

 

 

 

    <servlet-name>debugjsp</servlet-name>

 

 

 

    <description>Added to compile JSPs with debug info</description>

 

 

 

    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>

 

 

 

    <init-param>

 

 

 

      <param-name>classdebuginfo</param-name>

 

 

 

      <param-value>true</param-value>

 

 

 

    </init-param>

 

 

 

    <load-on-startup>3</load-on-startup>

 

 

 

  </servlet>

 

 

 

  <servlet-mapping>

 

 

 

    <servlet-name>RepositoryCategoryService</servlet-name>

 

 

 

    <url-pattern>/Repository/CategoryService</url-pattern>

 

 

 

  </servlet-mapping>

 

 

 

  <servlet-mapping>

 

 

 

    <servlet-name>action</servlet-name>

 

 

 

    <url-pattern>*.do</url-pattern>

 

 

 

  </servlet-mapping>

 

 

 

  <servlet-mapping>

 

 

 

    <servlet-name>debugjsp</servlet-name>

 

 

 

    <url-pattern>*.jsp</url-pattern>

 

 

 

  </servlet-mapping>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-template.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

  <taglib>

 

 

 

    <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>

 

 

 

    <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>

 

 

 

  </taglib>

 

 

 

</web-app>

 

 

 

 

 

 

 

2、   struts-config.xml

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

 

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

 

 

 

<struts-config>

 

 

 

  <global-forwards>

 

 

 

    <forward name="error" path="/error.jsp" />

 

 

 

    <forward name="root" path="/root.jsp" />

 

 

 

    <forward name="index" path="/index.htm" />

 

 

 

    <forward name="login" path="/startlogin.jsp" />

 

 

 

  </global-forwards>

 

 

 

  <action-mappings>

 

 

 

       <action   path="/ModuleSwitch"   type="org.apache.struts.actions.SwitchAction"/>

 

 

 

  </action-mappings>

 

 

 

  <message-resources parameter="com.cf.oa.ApplicationResources" />

 

 

 

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">

 

 

 

    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,                             /WEB-INF/validation.xml" />

  </plug-in>

 

 

 

</struts-config>

 

 

 

 

 

 

 

3、   struts-config-Repository.xml

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

 

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

 

 

 

<struts-config>

 

 

 

  <action-mappings>

 

 

 

    <action path="/Knowledge" type="com.clifford.repository.actions.KnowledgeAction">

 

 

 

      <forward name="0" path="/Script/GenericList.jsp" />

 

 

 

      <forward name="32" path="/Script/GenericInfo.jsp" />

 

 

 

      <forward name="10" path="/Script/MyDocList.jsp" />

 

 

 

      <forward name="30" path="/Script/DocEditForm.jsp" />

 

 

 

      <forward name="20" path="/Script/AdminPriCatList.jsp" />

 

 

 

    </action>

 

 

 

  </action-mappings>

 

 

 

</struts-config>

 

 

 

 

 

 

 

4、   struts-config-Exsample.xml

 

 

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

 

<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

 

 

 

<struts-config>

 

 

 

  <action-mappings>

 

 

 

    <action path="/Index" forward="/Script/Index.jsp"/>

 

 

 

  </action-mappings>

 

 

 

</struts-config>

 

 

 

 

 

 

 

从上面的配置文件中我们可以看到在web.xml中,添加了两个应用模块的自己的struts配置文件,其他的没有做任何变动。我们注要一下应用模块配置文件的规则,对于应用模块XXXX,那么它的struts配置文件为struts-config-XXXX.xml。如

 

 

 

    <init-param>

 

 

 

      <param-name>config/Repository</param-name>

 

 

 

      <param-value>/WEB-INF/struts-config-Repository.xml</param-value>

 

 

 

</init-param>

 

 

 

建议模块名,配置文件名 以及应用模块的目录名保持一致。

 

 

 

 

 

 

 

我们看一下各个Struts配置文件的作用:

 

 

 

struts-config.xml 文件是Struts的默认配置文件(当然这个文件也不是必须的),在我样例中主要是配置一些全局性的东西。如全局ForwardExceptionResource等等。在调用Action时,如果在其他模块配置文件中找不到,会自动在这个文件中找相应的Action。另外我将SwitchActin也放在这个文件中(等下我会说到这个Action的作用)。

 

 

 

 

 

 

 

struts-config-Repository.xmlstruts-config-Exsample.xml主要是用于各个应用模块的配置,在这个文件中可以独立地配置这个应用模块要用到的ActionActionForwordResource等等。在不同的文件中充许重名。

 

 

 

 

 

 

 

 

 

 

 

三、在各个模块中的Action跳转

 

 

 

如果要从一个模块的Action跳转到另一个模块的Action,有两种方法:

 

 

 

一种是直接指定路径,如<a href="/CliffordWeb/Exsample/Index.do">转到Exsample</a>

 

 

 

另一种是使用SwitchAction,这也就是我为什么要在struts-config.xml定义SwitchAction的原因。用法如下

 

 

 

<a href="/ CliffordWeb /ModuleSwitch.do?prefix=/Exsample&page=/Index.do">转到ExsampleSwitchAction</a>

 

 

 

两种方法原理上是一样的,可以根据自己的习惯来选择。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

内容概要:该PPT详细介绍了企业架构设计的方法论,涵盖业务架构、数据架构、应用架构和技术架构四大核心模块。首先分析了企业架构现状,包括业务、数据、应用和技术四大架构的内容和关系,明确了企业架构设计的重要性。接着,阐述了新版企业架构总体框架(CSG-EAF 2.0)的形成过程,强调其融合了传统架构设计(TOGAF)和领域驱动设计(DDD)的优势,以适应数字化转型需求。业务架构部分通过梳理企业级和专业级价值流,细化业务能力、流程和对象,确保业务战略的有效落地。数据架构部分则遵循五大原则,确保数据的准确、一致和高效使用。应用架构方面,提出了分层解耦和服务化的设计原则,以提高灵活性和响应速度。最后,技术架构部分围绕技术框架、组件、平台和部署节点进行了详细设计,确保技术架构的稳定性和扩展性。 适合人群:适用于具有一定企业架构设计经验的IT架构师、项目经理和业务分析师,特别是那些希望深入了解如何将企业架构设计与数字化转型相结合的专业人士。 使用场景及目标:①帮助企业和组织梳理业务流程,优化业务能力,实现战略目标;②指导数据管理和应用开发,确保数据的一致性和应用的高效性;③为技术选型和系统部署提供科学依据,确保技术架构的稳定性和扩展性。 阅读建议:此资源内容详尽,涵盖企业架构设计的各个方面。建议读者在学习过程中,结合实际案例进行理解和实践,重点关注各架构模块之间的关联和协同,以便更好地应用于实际工作中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值