一、需要的JAR文件为:Spring和Struts2框架本身需要的JAR文件以及他们所依赖的JAR文件
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>contextLoaderServlet</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- struts.enable.DynamicMethodInvocation = true,-动态方法调用,为true时,就可以在struts.xml配置“*”的通配符,来调用action里的方法 --> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <!-- 是否启用开发模式 --> <constant name="struts.devMode" value="true" /> <constant name="struts.action.extension" value=",do" /> <!-- 指定由spring负责action对象的创建 --> <constant name="struts.objectFactory" value="spring" /> <!-- struts配置文件改动后,是否重新加载 --> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 设置浏览器是否缓存静态内容 --> <constant name="struts.serve.static.browserCache" value="false" /> <!-- 该 default package中放置一些公共配置 --> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/WEB-INF/pages/public/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error" /> </global-exception-mappings> </package> <!-- 该 strutsAction package中放置action配置 --> <package name="strutsAction" namespace="/" extends="default"> <action name="index"> <result>index.jsp</result> </action> <action name="helloStrutsAction_*" class="com.vrv.paw.action.HelloStrutsAction" method="{1}"> <result name="{1}">/WEB-INF/pages/helloStrutsAction/{1}.jsp</result> </action> </package> </struts>
示例如下:
<bean id=”LoginAction” class=”yaso.struts.action.LoginAction”> <property name=”loginDao” ref=”LoginDao”/> </bean>
<action name=”LoginAction” class=”LoginAction”> <result name=”success”>/index.jsp</result> </action>