struts2的搭建及入门实例
一,准备
1,struts2所需文档及jar包
下载地址:http://struts.apache.org/download.cgi#struts20111
2,tomcat
下载地址:http://tomcat.apache.org/
二,入门实例
1,导入jar包
struts2-core-2.1.8.jar xwork-core-2.1.6.jar(webwork所依赖的开发包) freemarker-2.3.15.jar ognl-2.7.3.jar commons-fileupload-1.2.1.jar
2,web.xml配置
在WebRoo/WEB-INF/web.xml中加入
<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>
3,struts.xml配置
<package name="default" namespace="/" extends="struts-default"> <action name="hello"> <result>/Hello.jsp</result> </action> </package>
namespace说明:namespace决定了action的访问路径,默认为"",可以接收所有路径的action<br />
namespace可以写为/,或者/xxx,或者/xxx/yyy,对应的action访问路径为/index.action,
/xxx/index.action,或者/xxx/yyy/index.action
namespace最好也用模块来进行命名
action中没有class,会自动执行ActionSupport.java中的代码
public String execute() throws Exception{
return SUCCESS
}
4,Hello.jsp
随便添加文件