首先到Struts.apache.org去下载Struts2安装包,至少需要如下五个架包:
[color=red]struts2-core-2.0.11.1.jar xwork-2.0.4.jar
commons-logging-1.0.4.jar freemarker-2.3.8.jar
ognl-2.6.11.jar commons-io-1.3.2.jar
commons.fileupload-1.2.0.jar[/color]
[b](1)安装Struts2[/b]
struts1的入口点是一个servlet,而struts2的入口时一个过滤器(filter),配置在web.xml
[b](2)编写Action类[/b]
struts1中的动作类必须从Action类中继承,而Struts2的动作类需要从com.opensymphony.xwork2.ActionSupport类继承。
覆盖execute方法,没有参数,只返回一个String,用于表述执行结果。
[b](3)编写ActionForm类[/b]
在struts2中ActionForm和Action已经合二为一。ActionForm特性不再在Structs2中出现.简单的JavaBean即可对Action直接传递参数。不再需要全部使用String类型的参数。
[b](4)配置Action类[/b]
配置文件一般为struts.xml,放到WEB-INF的“classes”目录下。
在<struts>中可以有多个<package>,在<package>中可以有多个<action>
[color=red]注:[/color]struts1的动作类一般都以.do结尾,而struts2是以.action结尾。
[b](5)编写录入接口(jsp页面)[/b]
在struts2中只有一个标签库/struts-tags
[color=red]struts2-core-2.0.11.1.jar xwork-2.0.4.jar
commons-logging-1.0.4.jar freemarker-2.3.8.jar
ognl-2.6.11.jar commons-io-1.3.2.jar
commons.fileupload-1.2.0.jar[/color]
[b](1)安装Struts2[/b]
struts1的入口点是一个servlet,而struts2的入口时一个过滤器(filter),配置在web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filer-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
[b](2)编写Action类[/b]
struts1中的动作类必须从Action类中继承,而Struts2的动作类需要从com.opensymphony.xwork2.ActionSupport类继承。
覆盖execute方法,没有参数,只返回一个String,用于表述执行结果。
[b](3)编写ActionForm类[/b]
在struts2中ActionForm和Action已经合二为一。ActionForm特性不再在Structs2中出现.简单的JavaBean即可对Action直接传递参数。不再需要全部使用String类型的参数。
[b](4)配置Action类[/b]
配置文件一般为struts.xml,放到WEB-INF的“classes”目录下。
在<struts>中可以有多个<package>,在<package>中可以有多个<action>
[color=red]注:[/color]struts1的动作类一般都以.do结尾,而struts2是以.action结尾。
[b](5)编写录入接口(jsp页面)[/b]
在struts2中只有一个标签库/struts-tags