struts中多个模块时,使用多个struts-config.xml文件之间时如何切换的!
2008-01-27 18:15
501 查看
1.配置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/Add</param-name>
<param-value>/WEB-INF/struts-config_Add.xml</param-value>
</init-param>
<!-----------------这个是删除模块的-------------------------->
<init-param>
<param-name>config/Del</param-name>
<param-value>/WEB-INF/struts-config_Del.xml</param-value>
</init-param>
注释:Del和Add是模块的名字
2.配置每个struts-config.xml文件
a)struts-config.xml
<struts-config>
<data-sources />
<form-beans>
<form-bean name="login" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login"
type="del.Login"
name="login"
scope="request">
<forward name="success" contextRelative="true" path="/login.jsp"/>
</action>
</action-mappings>
</struts-config>
b)struts-config_Add.xml文件
<struts-config>
<data-sources />
<form-beans>
<form-bean name="add" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/Add/A"
type="del.Add"
name="add"
scope="request">
<forward name="success" contextRelative="true" path="/Add/A.jsp"/>
</action>
</action-mappings>
b)struts-config_Del.xml文件
<struts-config>
<data-sources />
<form-beans>
<form-bean name="del" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards/>
<action-mappings>
<action path="/Del/D"
type="del.Del"
name="del"
scope="request">
<forward name="success" contextRelative="true" path="/D.jsp"/>
</action>
</action-mappings>
</struts-config>
</struts-config>
3.测试
描述:我现在的Del模块下的MyJsp.jsp文件李想做如下操作:
a).本模块之间的跳转,跳到到D.jsp
代码如下:
MyJsp.jsp:
<form action="/Del/D.do">
<table>
<tr>
<td >
这是del-->del本模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
del.Del.java:
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
b)不同模块之间跳转Del--->Add,跳到:Add/A.jsp
MyJsp.jsp:
<form action="/Add/A.do">
<table>
<tr>
<td >
这是del--->add不同模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
Add.java
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
c)跳转到默认,如果你已经处在其他模块,需要转回到缺省模块
MyJsp.jsp
<form action="/login.do">
<table>
<tr>
<td >
这是del--->login默认模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
Login.java
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
4.结果:出现404错误,如下:
The requested resource (/Del/D.do) is not available等,请教高手啊!
<!-----------------这个是默认的-------------------------->
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<!-----------------这个是添加模块的-------------------------->
<init-param>
<param-name>config/Add</param-name>
<param-value>/WEB-INF/struts-config_Add.xml</param-value>
</init-param>
<!-----------------这个是删除模块的-------------------------->
<init-param>
<param-name>config/Del</param-name>
<param-value>/WEB-INF/struts-config_Del.xml</param-value>
</init-param>
注释:Del和Add是模块的名字
2.配置每个struts-config.xml文件
a)struts-config.xml
<struts-config>
<data-sources />
<form-beans>
<form-bean name="login" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login"
type="del.Login"
name="login"
scope="request">
<forward name="success" contextRelative="true" path="/login.jsp"/>
</action>
</action-mappings>
</struts-config>
b)struts-config_Add.xml文件
<struts-config>
<data-sources />
<form-beans>
<form-bean name="add" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/Add/A"
type="del.Add"
name="add"
scope="request">
<forward name="success" contextRelative="true" path="/Add/A.jsp"/>
</action>
</action-mappings>
b)struts-config_Del.xml文件
<struts-config>
<data-sources />
<form-beans>
<form-bean name="del" type="org.apache.struts.validator.DynaValidatorForm">
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards/>
<action-mappings>
<action path="/Del/D"
type="del.Del"
name="del"
scope="request">
<forward name="success" contextRelative="true" path="/D.jsp"/>
</action>
</action-mappings>
</struts-config>
</struts-config>
3.测试
描述:我现在的Del模块下的MyJsp.jsp文件李想做如下操作:
a).本模块之间的跳转,跳到到D.jsp
代码如下:
MyJsp.jsp:
<form action="/Del/D.do">
<table>
<tr>
<td >
这是del-->del本模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
del.Del.java:
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
b)不同模块之间跳转Del--->Add,跳到:Add/A.jsp
MyJsp.jsp:
<form action="/Add/A.do">
<table>
<tr>
<td >
这是del--->add不同模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
Add.java
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
c)跳转到默认,如果你已经处在其他模块,需要转回到缺省模块
MyJsp.jsp
<form action="/login.do">
<table>
<tr>
<td >
这是del--->login默认模块之间跳转:<button type="submit" on="image/active_login.png" off="image/inactive_login.png"></button>
</td>
</tr>
</table>
</form>
Login.java
public ActionForward execute(ActionMapping arg0, ActionForm arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// TODO Auto-generated method stub
return arg0.findForward("success");
}
4.结果:出现404错误,如下:
The requested resource (/Del/D.do) is not available等,请教高手啊!
相关文章推荐
- struts 使用多个配置文件 struts-config.xml
- struts 使用多个配置文件 struts-config.xml
- 如何使用 require.js ,实现js文件的异步加载,避免网页失去响应,管理模块之间的依赖性,便于代码的编写和维护。
- 如何使用多个Spring的xml配置文件(多模块配置)
- struts 使用多个配置文件 struts-config.xml
- 如何使用多个Spring的xml配置文件(多模块配置)
- 如何 在Spring MVC中 使用多个Spring和MyBatis的xml配置文件(多模块配置)
- spring如何使用多个xml配置文件
- 配置文件:persistence.xml-----beans.xml----jdbc.properties----log4j.properties---oscache----paoding---struts.config---web.xml
- struts中struts-config.xml文件解释
- 使用S2SH框架时,在配置struts.xml文件使用JSON返回类型出现错误
- spring如何使用多个xml配置文件
- struts2的使用技巧:struts.xml配置文件的编辑
- struts-config.xml配置文件
- 如何使用gdb给某个模块(文件)的所有函数下断点
- 如何使用.net实现iPhone和电脑之间的文件传输
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- 浅谈如何使用tinyxml解析xml文件
- struts-config.xml配置文件顺序异常: The content of element type "struts-config" must match
- Struts-config.xml配置文件讲解(一)