參考網址: http://blog.csdn.net/wangli61289/article/details/36662713
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