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
閱讀(8413)
評論(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.?敏捷軟件開發
搜索
積分與排名
積分 - 185366
排名 - 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——用戶登錄(15018)
2.?實戰struts2——Hello World(8413)
3.?《JBoss Seam:一個深度集成框架》pdf文件下載(8073)
4.?極限編程(5725)
5.?【翻譯】Spring 2.5架構圖(5331)
評論排行榜
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
主站蜘蛛池模板:
亚洲一区无码中文字幕
|
国产亚洲欧美日韩亚洲中文色
|
无码免费又爽又高潮喷水的视频
|
天堂在线免费观看中文版
|
成年18网站免费视频网站
|
久久精品国产亚洲AV麻豆王友容
|
久久国产精品免费一区
|
亚洲精品无码MV在线观看
|
可以免费观看的国产视频
|
久久久无码精品亚洲日韩蜜臀浪潮
|
日本精品久久久久久久久免费
|
一本久到久久亚洲综合
|
一本久久免费视频
|
国产亚洲精品精华液
|
91精品免费高清在线
|
精品久久亚洲中文无码
|
免费观看午夜在线欧差毛片
|
一级中文字幕乱码免费
|
亚洲成AV人片在线观看WWW
|
91久久精品国产免费直播
|
亚洲色偷精品一区二区三区
|
一区二区三区亚洲视频
|
a毛片在线免费观看
|
亚洲三级在线视频
|
亚洲欧洲精品成人久久曰影片
|
波霸在线精品视频免费观看
|
久久亚洲国产精品成人AV秋霞
|
成人在线视频免费
|
亚洲免费一区二区
|
亚洲国产成+人+综合
|
亚洲国产精品一区二区第一页免
|
亚洲日韩乱码久久久久久
|
日本高清免费不卡在线
|
www.av在线免费观看
|
亚洲视频免费一区
|
国产一级做a爱免费视频
|
久久久久久AV无码免费网站下载
|
国产亚洲人成网站观看
|
青青草免费在线视频
|
中文字幕免费在线看电影大全
|
亚洲免费观看网站
|