您的位置:首页 > 编程语言 > Java开发

如何快速地部属Struts2-学习Struts2开篇

2008-05-13 10:15 369 查看

如何快速地部属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



<?
xml version="1.0" encoding="ISO-8859-1"
?>



<!
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



<?
xml version="1.0" encoding="UTF-8"
?>



<!
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之一

参考:Max的Struts 2教材
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: