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++博客
博問
管理
<
2008年10月
>
日
一
二
三
四
五
六
28
29
30
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)
給我留言
查看公開留言
查看私人留言
隨筆分類
(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.?敏捷軟件開發
搜索
積分與排名
積分 - 185482
排名 - 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文件下載(8075)
4.?極限編程(5727)
5.?【翻譯】Spring 2.5架構圖(5333)
評論排行榜
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
主站蜘蛛池模板:
亚洲精品91在线
|
亚洲色偷偷av男人的天堂
|
亚洲精品一卡2卡3卡四卡乱码
|
99xxoo视频在线永久免费观看
|
亚洲av中文无码乱人伦在线咪咕
|
中文字幕无码毛片免费看
|
国产AV无码专区亚洲AWWW
|
a毛片成人免费全部播放
|
国产亚洲精品免费视频播放
|
日韩电影免费在线观看网址
|
最近国语视频在线观看免费播放
|
亚洲精品视频在线看
|
中文字幕免费视频精品一
|
超清首页国产亚洲丝袜
|
a级片在线免费看
|
亚洲综合久久综合激情久久
|
免费看污成人午夜网站
|
亚洲精品无码久久
|
亚洲国产中文v高清在线观看
|
国产精品午夜免费观看网站
|
久久精品国产亚洲av麻豆
|
1000部拍拍拍18勿入免费视频软件
|
亚洲同性男gay网站在线观看
|
成年人免费网站在线观看
|
特级毛片免费播放
|
亚洲AV日韩AV永久无码绿巨人
|
97国产免费全部免费观看
|
亚洲中文字幕无码久久2020
|
伊在人亚洲香蕉精品区麻豆
|
91久久精品国产免费一区
|
亚洲五月综合缴情婷婷
|
四虎影在线永久免费观看
|
国产真人无码作爱免费视频
|
亚洲视频一区在线播放
|
日韩精品视频免费在线观看
|
国产高潮久久免费观看
|
亚洲国产日产无码精品
|
亚洲AV无码成H人在线观看
|
久久狠狠躁免费观看2020
|
亚洲色精品三区二区一区
|
亚洲人成图片小说网站
|