?? struts vs spring 兩種mvc框架比較-開發頻道-java-天極網.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0038)http://dev.yesky.com/315/2069815.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網</TITLE>
<META
content="Struts VS Spring 兩種MVC框架比較,開發者網絡瞄準中國程序員群體,涵蓋軟件開發的各個技術層面,從Windows下的應用程序開發,到Java、Web開發、游戲開發和移動開發領域,均有相關教程和實例、技巧。 "
name=description>
<META
content="Struts VS Spring 兩種MVC框架比較,軟件開發,嵌入式開發,java開發工具,驅動開發,軟件工程,IBM,微軟,數據庫"
name=keywords>
<META content="天極網 | 全球中文IT第一門戶" name=author>
<META content="天極網 | 全球中文IT第一門戶" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META http-equiv=X-UA-Compatible content=IE=7><LINK media=all
href="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/y_mobile_content.css"
type=text/css rel=stylesheet>
<SCRIPT
src="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/showlay.js"></SCRIPT>
<META content="MSHTML 6.00.2900.3268" name=GENERATOR></HEAD>
<BODY><!--頁面頭部--><!--頭部-->
<DIV>
<SCRIPT
src="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/kingsoft-kuanban-071105.js"></SCRIPT>
</DIV>
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首頁</A>| <A
href="http://product.yesky.com/">產品報價</A>| <A
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手機</A>
| <A href="http://digital.yesky.com/">數碼</A> | <A
href="http://notebook.yesky.com/">筆記本</A> | <A
href="http://pc.yesky.com/">臺式機</A> | <A href="http://diy.yesky.com/">DIY硬件</A>
| <A href="http://oa.yesky.com/">外設</A> | <A href="http://net.yesky.com/">網絡</A>
| <A href="http://dh.yesky.com/">數字家庭</A> | <A
href="http://lab.yesky.com/">評測</A> | <A href="http://soft.yesky.com/">軟件</A> |
<A href="http://fashion.yesky.com/">e時代</A> | <A
href="http://game.yesky.com/">游戲</A> | <A href="http://pic.yesky.com/">圖片</A> |
<A href="http://desktop.yesky.com/">壁紙</A> | <A
href="http://q.yesky.com/">群樂</A> | <A href="http://my.yesky.com/">社區</A> | <A
href="http://blog.yesky.com/">博客</A> | <A
href="http://www.mydown.com/">下載</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A id=pagelogo href="http://www.yesky.com/"><IMG
alt=天極Yesky_全球中文IT第一門戶
src="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/logo.gif"
border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select()
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天極搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">廣州</A> <A
href="http://sz.yesky.com/">深圳</A><BR><A href="http://cd.yesky.com/">成都</A> <A
href="http://cq.yesky.com/">重慶</A> <A href="http://sy.yesky.com/">沈陽</A> <A
href="http://xa.yesky.com/">西安</A> </DIV>
<DIV class=rightarea_right><A
href="http://my.yesky.com/">用戶<BR>登錄</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/content_text_ad.js"
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="Struts VS Spring 兩種MVC框架比較-開發頻道-Java-天極網.files/flash.js"
type=text/javascript></SCRIPT>
<DIV id=childmenu twffan="done"><A href="http://soft.yesky.com/"
target=_self>軟件頻道></A><A href="http://dev.yesky.com/"
target=_self>程序開發></A><A href="http://dev.yesky.com/devjava/"
target=_self>Java</A><A href="http://dev.yesky.com/ysdevvb"
target=_self>VB</A><A href="http://dev.yesky.com/ysdevvc" target=_self>VC</A><A
href="http://dev.yesky.com/ysdevdelphi" target=_self>Delphi</A><A
href="http://dev.yesky.com/ysdevc" target=_self>C/C++</A><A
href="http://dev.yesky.com/web/" target=_self>Web開發</A><A
href="http://dev.yesky.com/msdn/" target=_self>微軟專欄</A><A
href="http://dev.yesky.com/devydkf/" target=_self>移動</A><A
href="http://dev.yesky.com/devsjk/" target=_self>數據庫</A><A
href="http://dev.yesky.com/ysdevcxrs" target=_self>程序人生</A><A
href="http://dev.yesky.com/ysdevrjgc" target=_self>軟件工程</A>|<A
href="http://soft.yesky.com/lesson/" target=_self>產品中心</A><A
href="http://www.mydown.com/soft/develop/news.shtml" target=_self>下載</A><A
href="http://www.ibm.com/developerworks/cn/onlinecourse/rational/r-mdatrend.html?S_TACT=105AGX52&S_CMP=tec.yesky">UML生成C++</A></DIV><!--導航條-->
<DIV id=location>
<DIV class=loleft>您現在的位置:<SPAN id=lo_links> <A
href="http://www.yesky.com/index.shtml">天極網</A> > <A
href="http://dev.yesky.com/index.shtml">開發頻道</A> </SPAN>> Struts VS Spring
兩種MVC框架比較</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--內容塊開始-->
<DIV id=conbox><!--左邊開始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://dev.yesky.com/315/2069815.shtml#pls"
target=_self>評論</A></DIV>
<DIV class=kr></DIV><!-- Error -->
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">圖片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
<!-- Error --></DIV></DIV></DIV>
<DIV class=topadbg style="PADDING-BOTTOM: 10px"><SPAN id=ad10></SPAN></DIV><A
name=top></A>
<DIV id=contitle>
<H1 id=artibodyTitle>Struts VS Spring 兩種MVC框架比較</H1></DIV>
<DIV id=conauthor><SPAN>2005-08-13 14:42 </SPAN><SPAN>作者: mandyhou
</SPAN><SPAN>出處: Java研究組織 </SPAN><SPAN>責任編輯:<A title=向本編輯提問
href="http://comments.yesky.com/t/·½ÖÛ/6,324/2069815.shtml" target=_blank>方舟</A>
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<DIV id=artibody>
<TABLE cellSpacing=1 cellPadding=2 width=600 align=center bgColor=#ff3300
border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD bgColor=#cc0000 colSpan=4><A
href="http://soft.yesky.com/lesson/"><FONT
color=#ffffff><B>天極軟件專題專區精選</B></FONT></A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://soft.yesky.com/tools/google">Google專區</A>
</TD>
<TD width="23%"><A href="http://soft.yesky.com/tools/popo">POPO專區</A></TD>
<TD width="24%"><A href="http://qq.yesky.com/">QQ專區</A> <A
href="http://soft.yesky.com/lesson/401/2047901.shtml">QQ掛機</A></TD>
<TD width="28%"><A
href="http://soft.yesky.com/327/2055327.shtml">了解Web2.0</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://design.yesky.com/flash/mx/">Flash MX
視頻教程</A></TD>
<TD width="23%"><A
href="http://soft.yesky.com/SoftChannel/72348986094125056/20040623/1823629.shtml">Photoshop視頻教程</A></TD>
<TD width="24%"><A
href="http://www.yesky.com/259/1926759.shtml">網頁設計視頻教程</A></TD>
<TD width="28%"><A
href="http://www.yesky.com/SoftChannel/72348986094125056/20050430/1943944.shtml">照片處理數字暗房</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A
href="http://www.yesky.com/SoftChannel/72348968914255872/20050517/1950125.shtml">PPT動畫演示教程</A></TD>
<TD width="23%"><A
href="http://soft.yesky.com/SoftChannel/72348968914255872/20050126/1905902.shtml">Excel動畫教程集</A></TD>
<TD width="24%"><A
href="http://soft.yesky.com/SoftChannel/72348968914255872/20050223/1914058.shtml">Word動畫演示教程</A></TD>
<TD width="28%"><A href="http://soft.yesky.com/os/vista/">Windows
Vista專區</A> </TD></TR>
<TR bgColor=#ffffff>
<TD width="25%" height=18><A
href="http://soft.yesky.com/security/muma/">特洛伊木馬專區</A></TD>
<TD width="23%" height=18><A
href="http://soft.yesky.com/security/hkjc/">黑客知識教程專區</A></TD>
<TD width="24%" height=18><A
href="http://soft.yesky.com//security/firewall/">防火墻應用專區</A></TD>
<TD width="28%" height=18><A
href="http://soft.yesky.com/os/zcb/">注冊表應用專區</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://soft.yesky.com/lesson/vbapi/"
target=_blank>Windows API開發專區</A></TD>
<TD width="23%"><A href="http://soft.yesky.com/lesson/network/"
target=_blank>網絡編程專區</A></TD>
<TD width="24%"><A href="http://soft.yesky.com/lesson/vbdatabase/"
target=_blank>VB數據庫編程專區</A></TD>
<TD width="28%"><A
href="http://soft.yesky.com/lesson/multimedia/">圖像處理與多媒體編程</A></TD></TR></TBODY></TABLE><BR> 基于Web的MVC framework在J2EE的世界內已是空前繁榮。TTS網站上幾乎每隔一兩個星期就會有新的MVC框架發布。目前比較好的MVC,老牌的有Struts、Webwork。新興的MVC 框架有Spring MVC、Tapestry、JSF等。這些大多是著名團隊的作品,另外還有一些邊緣團隊的作品,也相當出色,如Dinamica、VRaptor等。這些框架都提供了較好的層次分隔能力。在實現良好的MVC 分隔的基礎上,通過提供一些現成的輔助類庫,同時也促進了生產效率的提高。<BR><BR> 如何選擇一個好的框架應用在你的項目中,將會對你的項目的效率和可重用是至關重要的。本文將對目前最流行、最常用的兩種framework進行介紹。<BR><BR> 一、Struts<BR><BR> Struts是Apache<A
class=bluekey href="http://product.yesky.com/software/"
target=_blank>軟件</A>基金下Jakarta項目的一部分。Struts框架的主要架構<A class=bluekey
href="http://design.yesky.com/"
target=_blank>設計</A>和開發者是Craig R.McClanahan。Struts 是目前<A class=bluekey
href="http://dev.yesky.com/devjava/"
target=_blank>Java</A> Web MVC框架中不爭的王者。經過長達五年的發展,Struts已經逐漸成長為一個穩定、成熟的框架,并且占有了MVC框架中最大的市場份額。但是Struts某些技術特性上已經落后于新興的MVC框架。面對Spring MVC、Webwork2 這些設計更精密,擴展性更強的框架,Struts受到了前所未有的挑戰。但站在產品開發的角度而言,Struts仍然是最穩妥的選擇。<BR><BR> Struts有一組相互協作的類(組件)、Serlvet以及jsp tag lib組成。基于struts構架的web應用<A
class=bluekey href="http://dev.yesky.com/"
target=_blank>程序</A>基本上符合JSP Model2的設計標準,可以說是MVC設計模式的一種變化類型。根據上面對framework的描述,我們很容易理解為什么說Struts是一個web framwork,而不僅僅是一些標記庫的組合。但 Struts 也包含了豐富的標記庫和獨立于該框架工作的實用程序類。Struts有其自己的控制器(Controller),同時整合了其他的一些技術去實現模型層(Model)和視圖層(View)。在模型層,Struts可以很容易的與數據訪問技術相結合,包括EJB,JDBC和Object Relation Bridge。在視圖層,Struts能夠與JSP, Velocity Templates,XSL等等這些表示層組件想結合。<BR><BR> Struts的體系結構<BR><BR> struts framework是MVC 模式的體現,下面我們就從分別從模型、視圖、控制來看看struts的體系結構(Architecture)。 <BR><BR> 從視圖角度(View)<BR><BR> 主要由JSP建立,struts自身包含了一組可擴展的自定義標簽庫(TagLib),可以簡化創建用戶界面的過程。目前包括:Bean Tags,HTML Tags,Logic Tags,Nested Tags,Template Tags 這幾個Taglib。有關它們的詳細資料請參考struts用戶手冊<BR><BR> 從模型角度(Model)<BR><BR> 模型主要是表示一個系統的狀態(有時候,改變系統狀態的業務邏輯操作也也劃分到模型中)。在Struts中,系統的狀態主要有ActiomForm Bean體現,一般情況下,這些狀態是非持久性的。如果需要將這些狀態轉化為持久性數據存儲,Struts本身也提供了Utitle包,可以方便的與數據庫操作<BR><BR> 從控制器角度(Controller)<BR><BR> 在Struts framework中, Controller主要是ActionServlet,但是對于業務邏輯的操作則主要由Action、ActionMapping、ActionForward這幾個組件協調完成(也許這幾個組件,應該劃分到模型中的業務邏輯一塊)。其中,Action扮演了真正的業務邏輯的實現者,而ActionMapping和ActionForward則指定了不同業務邏輯或流程的運行方向。<BR>對于Struts 如何控制、處理客戶請求,讓我們通過對struts的四個核心組件介紹來具體說明。這幾個組件就是:ActionServlet。Action Classes,Action Mapping(此處包括ActionForward),ActionFrom Bean。<BR><BR> 二、Spring<BR><BR> Spring 實際上是Expert One-on-One J2EE Design and Development 一書中所闡述的設計思想的具體實現。在One-on-One 一書中,Rod Johnson 倡導J2EE 實用主義的設計思想,并隨書提供了一個初步的開發框架實現(interface21 開發包)。而Spring 正是這一思想的更全面和具體的體現。Rod Johnson 在interface21 開發包的基礎之上,進行了進一步的改造和擴充,使其發展為一個更加開放、清晰、全面、高效的開發框架。<BR><BR> Spring是一個開源框架,由Rod Johnson創建并且在他的著作《J2EE設計開發編程指南》里進行了描述。它是為了解決企業應用開發的復雜性而創建的。Spring使使用基本的JavaBeans來完成以前只可能由EJB完成的事情變得可能了。然而,Spring的用途不僅限于<A
class=bluekey href="http://product.yesky.com/catalog/850/"
target=_blank>服務器</A>端的開發。從簡單性、可測試性和松耦合的角度而言,任何Java應用都可以從Spring中受益。<BR><BR> 簡單來說,Spring是一個輕量的控制反轉和面向切面的容器框架。當然,這個描述有點過于簡單。但它的確概括出了Spring是做什么的。為了更好地理解Spring,讓我們分析一下這個描述: <BR><BR> 1、輕量,從大小與開銷兩方面而言Spring都是輕量的。完整的Spring框架可以在一個大小只有1MB多的JAR文件里發布。并且Spring所需的處理開銷也是微不足道的。此外,Spring是非侵入式的:典型地,Spring應用中的對象不依賴于輕量??從大小與開銷兩方面而言Spring都是輕量的。完整的Spring框架可以在一個大小只有1MB多的JAR文件里發布。并且Spring所需的處理開銷也是微不足道的。此外,Spring是非侵入式的:典型地,Spring應用中的對象不依賴于Spring的特定類。<BR><BR> 2、控制反轉??Spring通過一種稱作控制反轉(IoC)的技術促進了松耦合。當應用了IoC,對象被動地傳遞它們的依賴而不是自己創建或者查找依賴對象。你可以認為IoC與JNDI相反??不是對象從容器中查找依賴,而是容器在對象初始化時不等被請求就將依賴傳遞給它。 <BR><BR> 3、面向切面??Spring包含對面向切面編程的豐富支持,允許通過分離應用的業務邏輯與系統服務(例如審計與事物管理)進行內聚性的開發。應用對象只做它們應該做的??完成業務邏輯??僅此而已。它們并不負責(甚至是意識)其它的系統關注點,例如日志或事物支持。 <BR><BR> 4、容器??Spring包含和管理應用對象的配置和生命周期,在這個意義上它是一種容器。你可以配置你的每個bean如何被創建??基于一個配置原形為你的bean創建一個單獨的實例或者每次需要時都生成一個新的實例??以及它們是如何相互關聯的。然而,Spring不應該被混同于傳統的重量的EJB容器,它們經常是龐大與笨重的,難以使用。 <BR><BR> 框架:Spring使由簡單的組件配置和組合復雜的應用成為可能。在Spring中,應用對象被聲明式地組合,典型地是在一個XML文件里。Spring也提供了很多基礎功能(事務管理、持久性框架集成等等),將應用邏輯的開發留給了你。 <BR><BR> 所有Spring的這些特征使你能夠編寫更干凈、更可管理、并且更易于測試的代碼。它們也為Spring中的各種子框架提供了基礎。<BR><BR>
<DIV class=guanggao><SPAN id=contentAdv></SPAN></DIV></DIV></DIV><!--廣告代碼開始-->
<SCRIPT>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -