如何快速地部属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教材
相关文章推荐
- Python学习笔记4-如何快速的学会一个Python的模块、方法、关键字
- 【TX1学习与开发系列】(五)如何快速部署多个tx1系统(超细节版)
- 如何快速学习一门新语言?
- 如何快速学习新的编程语言
- 程序员职业思考与规划 --- 程序员如何快速学习一项新技术
- 2015062108 - 目前我如何快速学习
- 详细教程:如何快速在阿里云上构建机器学习应用?
- 详细教程:如何快速在阿里云上构建机器学习应用?
- 如何快速学习CMMI?
- 如何快速学习android开发的(一)
- YY一下如何快速学习<Thinking in Java>这本书
- 数据库学习(整理)----6--Oracle如何快速备份和多次备份数表数据
- 如何学习才能快速成为ios开发高手
- 如何快速的学习并使用一门语言工作-1(原创)
- 我是如何快速学习android开发的
- Wireshark学习笔记——如何快速抓取HTTP数据包
- 深度学习如何快速找到最佳学习率
- 对于一个成熟的程序员 如何快速正确的学习掌握新的语言
- android开发秘籍:如何快速学习复制其他产品UI
- .Net语言 APP开发平台——Smobiler学习日志:如何快速实现地图定位时的地点微调功能