struts 与spring 相关配置
?1) Mave2是一种管理项目整体构建过程的工具——包括编译,运行测试,生成报告以及管理构建的制品,其中对开发人员最有吸引力的一项就是对构建制品(artifact)进行管理。
?
?
?
?
?
?
?
2)web.xml
?
<filter>
?? <filter-name>Struts2</filter-name>?
?? <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
?
<filter-mapping>
??? <filter-name>Struts2</filter-name>
??? <url-pattern>/*</url-pattern>
</filter-mapping>
?
2、spring 配置;
装载Spring配置文件
?<!--
??Spring
??ApplicationContext配置文件的路径可使用*通配符,多个路径用*,号分隔此参数用于后面的Spring-Context
??loader
?-->
?<context-param>
??<param-name>contextConfigLocation</param-name>
??<param-value>classpath*:spring/applicationContext.xml</param-value>
?</context-param>
?
?
在“web.xml”配置文件中,你需要添加两部分代码。第一部分
用于注册一个 listener,来激活应用程序对象与 Spring的集成:
?
?
??<listener>
??<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
?</listener>
?
?
?
3)struts.xml
?
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "struts-2.1.dtd" ><struts><!--1、“struts-default.xml”和“struts-plugin.xml”就属于自动导入name :package唯一名字,如一个对像;namespace:链接的访问 http://xx.com/order/index.doextends : 如继承关系-->;<package name="order" namespace="/order" extends="struts-default,json-default"><!--拦截器定义,有点类似fillter --><interceptors><interceptor name="orderActionInterceptor" type="redirect">/common/500.html</result><result name="indexx" type="redirect">/common/indexx.html</result></global-results><!--http://xx.com/order/shoppingCart_success.domothod -> shoppingCartAction类里有个 success 方法shoppingCart_success.jsp 页面--><action name="shoppingCart_*" method="{1}" name="code"> <!-- 通配符配置,匹配所有的URL对action的访问 <constant name="struts.enable.SlashesInActionNames" value="true" /> action名可以有'/'字符 必需为true ${viewpath} controller返回的一个参数--><action name="*/*!*" method="{3}"> <result name="default" type="dispatcher">/{1}/{2}.jsp</result><result name="view" type="dispatcher">${viewpath}.jsp</result> <result name="redirect" type="redirect">${viewpath}</result></action><action name="*/*" type="dispatcher">/{1}/{2}.jsp</result><result name="view" type="dispatcher">${viewpath}.jsp</result><result name="redirect" type="redirect">${viewpath}</result></action>?
?http://xx.com/order/shoppingCart_success.do
mothod -> shoppingCartAction类里有个 success 方法
shoppingCart_success.jsp 页面
?
?
?
?
?
??
?
?
?
?
?
?
?
?
?
?
?
?
1 楼 a_bin 2011-09-13 >/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml