首先加jar
</pre><pre name="code" class="html"><struts>
<!-- 禁用动态方法访问 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<!-- 配置成开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- 配置拓展名为action -->
<constant name="struts.action.extention" value="action" />
<!-- 把主题配置成simple -->
<constant name="struts.ui.theme" value="simple" />
</struts>
禁用动态方法访问,例如果需要访问UserAction下得add方法,动态访问方式则为:user!add.action,可在配置文件中将这种访问方式禁用;
配置成开发模式:当有异常出现时对其补获,让其显示在浏览器上,可对面跳到相应错误页面
配置扩展名为action:当访问一个action时,后缀名必须加上action;
把主题配置成simple:不让浏览器在解析是加上其他样式元素
配置文件web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<display-name>study</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<struts>
<package name="test-action" namespace="/" extends="struts-default">
<action name="test_*" class="com.test.action.TestAction" method="{1}">
<result name="success">/WEB-INF/jsp/test/test.jsp</result>
</action>
</package>
</struts>
配置单个spring管理对象
<!-- 扫描service -->
<context:component-scan base-package="com.test.service.impl"></context:component-scan>
@Service("testService")
public class TestServiceImpl implements TestService {}
spring注入action(两种方式选择其中一种)
方式一:@Resource
TestService testService;
方式二:@Resource
public void setTestService(TestService testService) {
this.testService = testService;
}