我一直在使用struts 2,但出於幾個原因,我正在向Struts 1轉移(返回)。我想知道它們之間的主要區別,如關於程序可用性和一般流程。Struts 1和Struts 2的區別?
8
A
回答
2
Here是一個快速和完整的答案。換句話說,如果你可以,忘了Struts和只使用Struts2的...
1
是什麼原因迫使你回到沒有更積極發展的struts1?
可能有些人可以幫助你在這裏解決有關分歧的原因,經過以下幾個線程 Struts2 Vs Struts1
我也建議你到SO尋找更多的細節。我所知道的Struts2的設計和工作流程與struts1完全不同,它的開發也考慮到了struts1的侷限性。
11
讓我們來看看支柱1.x中的組件和功能差異和Struts 2.x的
In struts 1.x front controller is ActionServlet
In 2.x front controller is FilterDispatcher
In struts 1.x we have RequestProcessor class
In 2.x we have Interceptors instead RequestProcessor will see about this concept later just remember as of now
In struts 1.x we have multiple tag libraries like, html, logic, bean..etc
In 2.x we do not have multiple libraries, instead we have single library which includes all tags
In struts 1.x the configuration fine name can be [any name].xml and we used to place in web-inf folder
In 2.x the configuration file must be struts.xml only and this must be in classes folder
In struts 1.x we have form beans and Action classes separately
In 2.x form bean, Action classes are combinedly given as Action class only, of course we can take separately if we want ;)
In struts 1.x properties file must be configured in struts-config.xml
But in 2.x we need to configure our resource bundle(s) in struts.properties file
In struts 1.x we have programmatic and declarative validations only
In 2.x we have annotations support too along with programmatic and declarative validations
功能差異
Struts的1和2的In struts 1.x declarative validations are done by using validation frame work
In 2.x, declarative validations are done by using xwork2 frame work by webwork the reason being, its support valuations through Annotations
In struts 1.x an Action class is a single ton class, so Action class object is not a thread safe, as a programmer we need to make it as thread safe by applying synchronization
In 2.x an Action class object will be created for each request, so it is by default thread safe, so we no need to take care about safety issues here
In struts 1.x we have only jsp as a view technology
In 2.x we have support of multiple view technologies like velocity, Freemarker, jasper reports, jsp bla bla
In struts 1.x Action class is having servlet dependency, because in execute() method accepts req, res parameter right ! so.
In 2.x Action class doesn’t have any servlet dependency, because its execute() method doesn’t accepts any parameters, however we can access all servlet objects with dependency injection
2
比較由Struts的創作者(Apache軟件基金會)
Comparing Struts 1 and Struts 2
這裏是上面提到的鏈接可用的內容,如果他們決定在將來更改鏈接或刪除頁面,則納入其中。
動作類
- 的Struts 1
要求Action類繼承一個抽象基類。 Struts 1中的一個常見問題是編程抽象類而不是接口。 - Struts 2
Action可以實現Action接口以及其他接口以啓用可選和自定義服務。 Struts 2提供了一個基本的ActionSupport類來實現常用的接口。儘管如此,Action界面是而不是必需的。任何帶有執行簽名的POJO對象都可以用作Struts 2 Action對象。
- 的Struts 1
線程模型
- 的Struts 1個
操作是單獨且必須是線程安全的,因爲只會有一個類的一個實例來處理該行動的所有請求。單例策略限制了Struts 1 Actions可以做什麼,並且需要額外注意開發。操作資源必須是線程安全的或同步的。 - Struts 2
爲每個請求實例化動作對象,所以沒有線程安全問題。 (實際上,servlet容器生成每個請求的許多扔掉的物品,還有一個對象不徵收性能下降或影響垃圾收集。)
- 的Struts 1個
Servlet的依賴
- Struts 1
由於在調用Action時將HttpServletRequest和HttpServletResponse傳遞給execute方法,操作依賴於servlet API。 - Struts 2
操作未耦合到容器。大多數情況下,servlet上下文都表示爲簡單的映射,允許單獨測試動作。如果需要,Struts 2 Actions仍然可以訪問原始請求和響應。但是,其他架構元素可以減少或消除直接訪問HttpServetRequest或HttpServletResponse的需求。
- Struts 1
可測性
- 的Struts 1
的一個主要障礙測試支桿操作是,執行方法公開了Servlet API。第三方擴展Struts TestCase爲Struts 1提供了一組模擬對象。 - Struts 2
支持通過攔截器堆棧爲每個Action創建不同的生命週期。根據需要,可以創建自定義堆棧並使用不同的操作。
可以通過實例化Action,設置屬性和調用方法來測試Struts 2操作。依賴注入支持也使測試更簡單。
- 的Struts 1
收穫輸入
- 的Struts 1
使用一個ActionForm對象捕獲輸入。與Actions類似,所有ActionForms都必須擴展基類。由於其他JavaBean不能用作ActionForms,因此開發人員通常會創建冗餘類來捕獲輸入。 DynaBeans可用作創建傳統ActionForm類的替代方法,但在這裏,開發人員也可能會重新描述現有的JavaBeans。 - Struts 2
使用動作屬性作爲輸入屬性,消除了對第二個輸入對象的需要。輸入屬性可以是豐富的對象類型,它可以有自己的屬性。 Action屬性可以通過taglibs從網頁訪問。 Struts 2還支持ActionForm模式,以及POJO表單對象和POJO動作。豐富的對象類型(包括業務或域對象)可用作輸入/輸出對象。 ModelDriven特性簡化了對POJO輸入對象的taglb引用。
- 的Struts 1
- 表達語言
- 的Struts 1
集成了JSTL,所以它使用JSTL EL。 EL具有基本的對象圖遍歷,但收集和索引屬性支持相對較弱。 - Struts 2
可以使用JSTL,但該框架還支持更強大和靈活的表達式語言,稱爲「對象圖表符號語言」(OGNL)。
- 的Struts 1
- 綁定值到瀏覽
- 的Struts 1
用途爲對象綁定到頁面上下文的訪問標準的JSP機制。 - Struts 2
使用「ValueStack」技術,以便taglib可以在不將視圖耦合到它所呈現的對象類型的情況下訪問值。 ValueStack策略允許在可能具有相同屬性名稱但屬性類型不同的一系列類型中重複使用視圖。
- 的Struts 1
- 類型轉換
- 的Struts 1個
ActionForm屬性通常是所有字符串。 Struts 1使用Commons-Beanutils進行類型轉換。轉換器是按類的,每個實例都不可配置。 - Struts 2
使用OGNL進行類型轉換。該框架包含用於基本和常見對象類型和基元的轉換器。
- 的Struts 1個
- 驗證
- 的Struts 1
支持通過對ActionForm的一個validate方法手動驗證,或通過一個擴展共享驗證。對於同一個類,類可以有不同的驗證上下文,但不能鏈接到子對象上的驗證。 - Struts 2
支持通過驗證方法和XWork驗證框架進行手動驗證。 Xwork驗證框架支持使用爲屬性類類型和驗證上下文定義的驗證將鏈接驗證轉換爲子屬性。
- 的Struts 1
- 控制動作執行
- 的Struts 1
支承體用於每個模塊單獨的請求處理器(生命週期),但是在該模塊中的所有操作必須共享相同的生命週期。 - Struts 2
支持通過攔截器堆棧爲每個Action創建不同的生命週期。根據需要,可以創建自定義堆棧並使用不同的操作。
- 的Struts 1
相關問題
- 1. 運行Struts 1和Struts 2
- 2. Struts 1.x vs Struts 2.x
- 3. Struts-Struts 2中的I18n
- 4. Apache Struts和Java EE之間的區別?
- 5. Struts 2 - struts標記錯誤
- 6. Apache NetUI和Struts有什麼區別?
- 7. DynamicJasper + Struts 1
- 8. zk with struts 1
- 9. 從非struts 2 action訪問struts 2 jsp
- 10. 使用Struts實現Struts 2攔截器1
- 11. 將struts 2動作重定向到struts 1動作
- 12. Struts 1和連接池
- 13. struts.xml和struts-config.xml
- 14. Struts 2 dispatcher
- 15. Dropdown struts 2
- 16. Struts 2 subaction
- 17. Struts 1 - 行提交
- 18. Struts 2和瓷磚與Netbeans
- 19. Struts 2 REST和驗證
- 20. 彈簧安全和Struts 2
- 21. 從Struts 1.x遷移到GWT 2.x
- 22. 磚的Struts 2 NoSuchDefinitionException
- 23. RAD中的Struts 2
- 24. 關於Struts 2和Struts-jQuery Autocompleter的問題
- 25. Struts 1.x到Struts 2.x Scriptlet在s:textarea字段中的遷移問題
- 26. Netbeans支持struts 2?
- 27. 升級struts 2 jar
- 28. Struts 2會話值
- 29. Scrumbars for Struts 2 tiles
- 30. Struts 2安全性
祝你通過引用http://www.ollahero.com/2011/09/15/struts1-vs-struts2/ http://www.java-samples.com/showtutorial .php?tutorialid = 200 –
我希望你回到Struts 1的唯一理由是因爲你的公司正在讓你 - 從技術/生產力的角度來看,它是一種首選的方式。 –
@DaveNewton同意你的看法,因爲我自己可以看到從struts1轉向struts2的理由,但反之亦然。 「 –