如何快速地部属Struts2
开发工具-Eclipse Struts2.0
从新建Web/Dynamic Web Project开始
不说简单的了,只说几点要特别注意的
1.应用Struts2
将xwork-2.0.4.jar、commons-logging-1.0.4.jar、freemarker-2.3.8.jar、ognl-2.6.11.jar、struts2-core-2.0.11.jar这几个包copy到web程序的lib下。其它的不要。否则发布的时候会报:Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean错误
原因是:If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
2.部属
(1)web.xml
<! DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
< web-app >
< display-name > Struts 2.0 Hello World </ display-name >
< filter >
< filter-name > struts2 </ filter-name >
< filter-class > org.apache.struts2.dispatcher.FilterDispatcher </ filter-class >
</ filter >
< filter-mapping >
< filter-name > struts2 </ filter-name >
< url-pattern > /* </ url-pattern >
</ filter-mapping >
< welcome-file-list >
< welcome-file > index.html </ welcome-file >
</ welcome-file-list >
</ web-app >
Struts中默认的web.xml配置如上
(2)struts.xml
<! DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd" >
< struts >
< include file ="struts-default.xml" />
< package name ="tutorial" extends ="struts-default" >
< action name ="HelloWorld" class ="tutorial.HelloWorld" >
< result > HelloWorld.jsp </ result >
</ action >
</ package >
</ struts >
Struts中默认的struts.xml配置如上
注:文件名必须为struts.xml
3.Action Class
继承ActionSupport(com.opensymphony.xwork2.ActionSupport)
实现execute
返回ERROR,INPUT,LOGIN,NONE,SUCCESS之一