搭建struts的项目Hellow World
搭建开发与运行环境步骤:
1、到Apache下载Struts 2.0包。struts2.1.6至少需要如下个jar包(commons-logging-1.0.4.jar 日志包、freemark- 2.3.8.jar、ognl-2.6.11.jar、struts2-core-2.0.11.jar 核心包、xwork-2.0.4.jar xwork所依赖的核心包,struts2也依赖、commons-fileupload-1.2.1)
2、新建Web 项目Hellow World
3、导入struts所需要的lib文件,
4、配置web配置文件,配置struts过滤器如下
<filter> <filter-name>struts2</filter-filter-name> <fileter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*<url-pattern> </filter-mapping>
5、配置struts配置文件
<?xml version="1.0" encoding="GBK"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="smpBasic" extends="struts-default" namespace="/smp"> <interceptors> <interceptor name="parameterTrimer" class="com.fortune.smp.server.interceptors.ParameterTrimer"> </interceptor> <interceptor-stack name="smpDefaultStack"> <interceptor-ref name="parameterTrimer"></interceptor-ref> <interceptor-ref name="defaultStack"> <param name="exception.logEnabled">true</param> <param name="exception.logLevel">info</param> </interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name="smpDefaultStack"></default-interceptor-ref> <global-results> <result>${targetURL}</result> <result name="redirectTo" type="redirect">${targetURL}</result> <result name="chainTo" type="chain">${targetURL}</result> <result name="streamTo" type="stream">${targetURL}</result> </global-results> <action name="*-*" class="com.fortune.smp.server.action.{1}Action" method="{2}"> </action> </package> </struts>
Tips:
1.可在Snippets为struts2.xml自定义代码片段,例如声明文件头
2.导入struts2.0dtd文件,增加strtus.xml自动提示功能