多模块问题;
是要多个配制文件。
比方说:凳陆问题,有管理凳陆,有销售凳陆。。。。。。
举例;
现有一个默认的配制文件夹(struts-config.xml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings >
<action path="/quary" type="prj19.action.QuaryAction" />
</action-mappings>
<message-resources parameter="prj19.ApplicationResources" />
</struts-config>
------------------------------------------------------------------------------
创建一个新的配制文件(struts-config-sale.xml)如下;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings >
<action path="/quary" type="prj19.action.QuaryInSaleAction" />
</action-mappings>
<message-resources parameter="prj19.ApplicationResources" />
</struts-config>
从上面可以看到,两个不同的Action取的名字是相同的(path="/quary"),
这是里为了测试调用哪个Action,
------------------------------------------------------------------------
现创建一个p1.jsp
<%@ page language="java" pageEncoding="gb2312"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
</head>
<body>
<html:link action="/quary.do">默认模块</html:link>
<html:link action="/quary.do" module="/">默认模块</html:link>
<html:link action="/sale/quary.do">sale模块</html:link>
<html:link action="/quary.do" module="/sale">sale模块</html:link>
</body>
</html>
前两个模块是一样的。只是两种不同的方法而已。
后两个模块是一样的。只是两种不同的方法而已。
---------------------------------------------------------------------
要系统能认识刚刚的struts-config-sale.xml就必须在web.xml中注册。
如下:
//默认的
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
//创建的
<init-param>
<param-name>config/sale</param-name>//sale是给模块起个名称
<param-value>/WEB-INF/struts-config-sale.xml</param-value>
</init-param>
-----------------------------------------------------------------------------------------------------
为了实现上面的功能。还有一种不常用的方法:如下;
只要在struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans />
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/quary" type="prj19.action.QuaryAction" />
<!-- 第三种方法:SwitchAction -->
<action path="/switch"
type="org.apache.struts.actions.SwitchAction" />
</action-mappings>
<message-resources parameter="prj19.ApplicationResources" />
</struts-config>
--------------------------------------------------------
在JSP中测试
<%@ page language="java" pageEncoding="gb2312"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
</head>
<body>
<html:link action="/quary.do">默认模块</html:link>
<html:link action="/quary.do" module="/">默认模块</html:link>
<html:link action="/sale/quary.do">sale模块</html:link>
<html:link action="/quary.do" module="/sale">sale模块</html:link>
<!-- 第三种方式 -->
<html:link action="/switch.do?prefix=/sale&page=/quary.do">sale模块</html:link>
<html:link action="/switch.do?prefix=&page=/quary.do">默认模块</html:link>
</body>
</html>
多个模块可以分开开发,最后可以结合。