参考网址:
1、引入需要的JAR包
<!-- struts2依赖包 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.14</version>
</dependency>
<!-- struts restful 依赖包 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-rest-plugin</artifactId>
<version>2.3.14</version>
</dependency>
2、修改struts.xml配置文件
<struts>
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.devMode" value="false" />
<!-- struts2 restful -->
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<include file="struts-default.xml" />
</struts>
3、修改web.xml配置文件
<web-app>
<display-name>Archetype Created Web Application</display-name>
<init-param>
<param-name>config</param-name>
<!-- <param-value>../../resources/struts.xml</param-value> -->
<param-value>classpath:struts.xml</param-value>
</init-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>/*</url-pattern>
</filter-mapping>
<!-- log4j -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</context-param>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
4、编写Controller
Controller上面使用如下注解
@Results({
@Result(name="success", type="redirectAction", params = {"actionName" , "orders"})
})
5、编写JSP页面
JSP页面需要放到WEB-INF下面的content目录下,页面命名采用controller中的actionName+方法名;
如orders-index.jsp、orders-show.jsp
参考代码:
http://download.csdn.net/detail/hutudanvip/8394941