Chinese => English
『一只小螞蟻』的專欄
BlogJava
|
首頁
|
發新隨筆
|
發新文章
|
聯系
|
聚合
|
管理
隨筆:135 文章:0 評論:250 引用:0
實戰struts2——Hello World
內容提要
:本文以一個“Hello World”的簡單Demo,開始struts2之旅。
開發環境
:myeclipse5.0+eclipse3.2+jdk5.0+tomcat5.5+struts2+junit3.8
項目目錄結構
:
其中lib目錄中,包含struts2相關的jar文件。本項目中,為簡單起見,選用了struts-2.0.1\lib中的所有jar文件(注意:
不需要包含
struts2-all-2.0.1.jar)。
項目文件
:
1. Action類
com.cleversoft.struts2.demo.HelloWorld.java:
package
?com.cleversoft.struts2.demo;
import
?com.opensymphony.xwork2.ActionSupport;
public
?
class
?HelloWorld?
extends
?ActionSupport?
{
????
/**?*/
/**
?????*?
?????
*/
????
private
?
static
?
final
?
long
?serialVersionUID?
=
?
-
758686623642845372L
;
????
public
?
static
?
final
?String?MESSAGE?
=
?
"
Hello,?Struts2!
"
;
????
public
?String?execute()?
throws
?Exception?
{
????????setMessage(MESSAGE);
????????
return
?SUCCESS;
????}
????
private
?String?message;
????
public
?
void
?setMessage(String?message)?
{
????????
this
.message?
=
?message;
????}
????
public
?String?getMessage()?
{
????????
return
?message;
????}
}
2. View頁面
HelloWorld.jsp:
<%
@?taglib?prefix
=
"
s
"
?uri
=
"
/struts-tags
"
%>
<
html
>
????
<
head
>
????????
<
title
>
Hello?World!
</
title
>
????
</
head
>
????
<
body
>
????????
<
h2
>
????????????
<
s:property?
value
="message"
?
/>
????????
</
h2
>
????
</
body
>
</
html
>
3. 配置Action
struts.xml:
<!
DOCTYPE?struts?PUBLIC
????"-//Apache?Software?Foundation//DTD?Struts?Configuration?2.0//EN"
????"http://struts.apache.org/dtds/struts-2.0.dtd"
>
<
struts
>
????
<
package?
name
="com.cleversoft.struts2.demo"
?extends
="struts-default"
>
????????
<
action?
name
="HelloWorld"
?class
="com.cleversoft.struts2.demo.HelloWorld"
>
????????????
<
result
>
/HelloWorld.jsp
</
result
>
????????
</
action
>
????????
<!--
?Add?your?actions?here?
-->
????
</
package
>
</
struts
>
struts.properties(可選):
struts.devMode?
=
?true
struts.enable.DynamicMethodInvocation?
=
?false
4. web配置
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?Demo
</
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
>
5. 測試類
com.cleversoft.struts2.test.HelloWorldTest.java:
package
?com.cleversoft.struts2.test;
import
?junit.framework.TestCase;
import
?com.opensymphony.xwork2.ActionSupport;
import
?com.cleversoft.struts2.demo.
*
;
public
?
class
?HelloWorldTest?
extends
?TestCase?
{
????
public
?
void
?testHelloWorld()?
throws
?Exception?
{
????????HelloWorld?hello_world?
=
?
new
?HelloWorld();
????????String?result?
=
?hello_world.execute();
????????assertTrue(
"
Expected?a?success?result!
"
,?ActionSupport.SUCCESS
????????????????.equals(result));
????????assertTrue(
"
Expected?the?default?message!
"
,?HelloWorld.MESSAGE
????????????????.equals(hello_world.getMessage()));
????}
}
6. 其他
index.html:
<!
DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"
>
<
html
>
??
<
head
>
????
<
title
>
index.html
</
title
>
????
????
<
meta?
http-equiv
="keywords"
?content
="keyword1,keyword2,keyword3"
>
????
<
meta?
http-equiv
="description"
?content
="this?is?my?page"
>
????
<
meta?
http-equiv
="content-type"
?content
="text/html;?charset=GB18030"
>
????
????
<!--
<link?rel="stylesheet"?type="text/css"?href="./styles.css">
-->
??
</
head
>
??
??
<
body
>
????This?is?Struts?2.0?Demo?page.?
<
br
>
??
</
body
>
</
html
>
7. 運行
訪問
http://localhost:8080/struts2/HelloWorld.action
運行結果:
參考資料:
1.
為Struts 2.0做好準備
2.
Getting Started
歡迎大家訪問我的個人網站
萌萌的IT人
發表于 2007-01-24 22:34
Thomas
閱讀(8417)
評論(1)
編輯
收藏
評論
#
re: 實戰struts2——Hello World
* 正在學習:陷阱技(等級10)
* 剩余時間:571:31:50 完成時間:11-09 08:23
* 取消
xu
評論于 2008-10-16 13:00
回復
更多評論
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
<
2007年1月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(9)
給我留言
查看公開留言
查看私人留言
隨筆分類
(138)
Agile(3)
(rss)
AppFuse(1)
(rss)
Apusic OperaMasks(1)
(rss)
Books(1)
(rss)
Business & Finance(1)
(rss)
DDD(2)
(rss)
Design Patterns(1)
(rss)
Eclipse(4)
(rss)
EJB3.0
(rss)
Groovy & Grails
(rss)
Hibernate(3)
(rss)
Internet
(rss)
J2EE核心模式(2)
(rss)
Java ABC(4)
(rss)
Java EE(6)
(rss)
JavaScript & Ajax(2)
(rss)
JBoss Seam(5)
(rss)
JPA(1)
(rss)
JSF(2)
(rss)
Life(15)
(rss)
Open Source(3)
(rss)
Other(40)
(rss)
Portal(1)
(rss)
Pylons學習(3)
(rss)
Python(2)
(rss)
Security(2)
(rss)
Spring(3)
(rss)
TDD(3)
(rss)
Writing(1)
(rss)
一周閱讀推薦(3)
(rss)
螞蟻學模式(23)
(rss)
隨筆檔案
(135)
2007年11月 (9)
2007年10月 (5)
2007年9月 (10)
2007年8月 (13)
2007年7月 (8)
2007年6月 (7)
2007年5月 (10)
2007年4月 (10)
2007年3月 (4)
2007年2月 (5)
2007年1月 (12)
2006年12月 (13)
2006年11月 (7)
2006年10月 (2)
2006年9月 (15)
2006年8月 (4)
2006年7月 (1)
相冊
Technology
收藏夾
(38)
Design Patterns(3)
(rss)
InfoQ(9)
(rss)
Java(1)
(rss)
JBoss Seam(6)
(rss)
My Articles(11)
(rss)
Reading(8)
(rss)
About me
my "douban" on douban
my "fanfou" on fanfou
my blog on baidu
my bookmarks on del.icio.us
my photos on picasaweb
Blogs
Anders小明的Blog
BlueDavy之技術Blog
Chris Richardson
gigix
Martin Fowler
Michael Yuan
robbin
夢想風暴
江南白衣
簡單就是美!
胡長城(銀狐999)BLOG
良葛格學習筆記
蛟龍居
鍵盤上的舞者
Classmates
碧濤居
Coworkers
一個基督徒的在世歷程
English
BBC China
普特英語聽力
Friends
BeanSoft
main()
劉玉輝
雙魚瓶
小獻
曹江華
阿蜜果
Java
BlogJava
Blogs Summary
DevX: Java Zone
DZone
Huihoo
IBM developerWorks 中國
InfoQ
JAVA DEVELOPER'S JOURNAL
javablogs
JavaEye
javapassion.com
JavaWorld
Java站點
JBoss Seam中文站
JCP
Java Community Process
J道
Object Mentor Blog
ONJava
Raible Designs | Java
TSS
Open Source
appfuse
EasyJF
Java開源大全
JBoss Seam
OperaMasks.org
OSGi.org.cn
PicoContainer
projecttrack
Project Track - a JSF/Spring/Hibernate/Acegi example application
Redsaga
SpringSide
最新隨筆
1.?【轉載】你的時間在那里,成就就在那里
2.?Seam能否取代Struts?
3.?【一周閱讀推薦】2007.11.05—2007.11.11
4.?選擇Seam的十大理由
5.?《JBoss Seam:一個深度集成框架》pdf文件下載
6.?在JBoss AS下部署Seam示例程序
7.?【翻譯】Spring 2.5架構圖
8.?【一周閱讀推薦】2007.10.29—2007.11.04
9.?JBoss Seam中文站發布
10.?web2.0最全的國外API應用集合
11.?【一周閱讀推薦】2007.10.22—2007.10.28
12.?記住,你的兜里只有100塊!
13.?【轉載】我最恐懼的事情是競爭力的喪失
14.?【翻譯】RIA入門知識
15.?【翻譯】比較NetBeans 6.0 M10和IntelliJ IDEA 7.0 M1
16.?【轉載】Web2.0@China!
17.?【轉載】正確地做事與做正確的事同樣重要
18.?【轉載】你必須要有一樣拿得出手
19.?極限編程
20.?敏捷軟件開發
搜索
積分與排名
積分 - 186812
排名 - 311
最新評論
1.?viagra sale
Hello!
--viagra_sale
2.?generic cialis paypal payment
Hello!
--cialis
3.?re: 【轉載】你的時間在那里,成就就在那里
很多東西也就深明大意了 路就走的更遠了
--水泵
4.?re: 實戰struts2——用戶登錄
請問你的web。xml 是怎么寫的
--111222
5.?re: 【翻譯】不使用Spring的5個理由
在你需要的時候使用
--haremeat
閱讀排行榜
1.?實戰struts2——用戶登錄(15031)
2.?實戰struts2——Hello World(8417)
3.?《JBoss Seam:一個深度集成框架》pdf文件下載(8088)
4.?極限編程(5737)
5.?【翻譯】Spring 2.5架構圖(5341)
評論排行榜
1.?【翻譯】不使用Spring的5個理由(27)
2.?J2EE without AJAX——Apusic OperaMasks框架簡介(16)
3.?《JBoss Seam:一個深度集成框架》pdf文件下載(15)
4.?【翻譯】Spring 2.5架構圖(14)
5.?【轉載】你的時間在那里,成就就在那里(12)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 Thomas
主站蜘蛛池模板:
亚洲伊人久久成综合人影院
|
亚洲国产香蕉人人爽成AV片久久
|
亚洲欧美aⅴ在线资源
|
国产免费一区二区三区VR
|
本道天堂成在人线av无码免费
|
国产精品亚洲A∨天堂不卡
|
亚洲国产高清人在线
|
国产成人免费网站
|
一区二区在线视频免费观看
|
无码av免费毛片一区二区
|
黄色片网站在线免费观看
|
麻豆亚洲AV永久无码精品久久
|
色se01短视频永久免费
|
老司机免费午夜精品视频
|
少妇中文字幕乱码亚洲影视
|
日本高清色本免费现在观看
|
久久久久久久99精品免费观看
|
亚洲精品第一国产综合野
|
亚洲中文字幕无码不卡电影
|
最近最新的免费中文字幕
|
国产午夜无码精品免费看动漫
|
亚洲AV无码成人网站在线观看
|
亚洲人成影院在线
|
亚洲免费一区二区
|
啦啦啦高清视频在线观看免费
|
波多野结衣免费一区视频
|
亚洲AV无码乱码国产麻豆
|
男女啪啪永久免费观看网站
|
99久久久国产精品免费牛牛
|
三级黄色片免费看
|
亚洲AV无码一区二区一二区
|
久久综合亚洲色HEZYO社区
|
久久国产精品成人片免费
|
猫咪www免费人成网站
|
国产精品亚洲专区在线观看
|
亚洲AV无码欧洲AV无码网站
|
伊在人亚洲香蕉精品区麻豆
|
在线观看无码的免费网站
|
最近中文字幕完整免费视频ww
|
男女一边桶一边摸一边脱视频免费
|
亚洲精品日韩中文字幕久久久
|