`
zhb8015
  • 浏览: 377440 次
  • 性别: Icon_minigender_1
  • 来自: 北京
博客专栏
Group-logo
Spring Roo杂谈
浏览量:0
社区版块
存档分类
最新评论

Stripes vs struts2

    博客分类:
  • java
阅读更多
 
 
Skip to end of metadata
 
Go to start of metadata
 

Here are some quick comparison points between Stripes and Struts2:

 

Stripes

Struts2

Version

Configuration

Main workhorse

Response mechanism

View technology

Layout mechanism

Binding mechanism

Validation

Validation short-circuiting

Custom validation

Model-to-view data transfer

Type conversion

Formatting

Custom module configuration

Interceptors

Localization

1.5

2.0.12

web.xml

web.xmlstruts.xml, optionally struts.properties and others

Classes that implement ActionBean

Classes that have an execute() method, optionally implementAction, or extend ActionSupport

Instance of Resolution

String identifier that maps to a result in struts.xml or in an annotation

JSP or FreeMarker

JSP, FreeMarker, or Velocity

Built-in, with three layout tags. For people who like Tiles or SiteMesh, they can be used as well.

Tiles or SiteMesh

Built-in

OGNL

@Validate and @ValidateNestedProperties

Configure in an XML file, or use annotations

Built-in, configurable with when=ValidationState.ALWAYS andValidation.InvokeValidateWhenErrorsExist

Set short-circuit="true" on <field-validator>

Annotate your method with @ValidationMethod

Extend either ValidatorSupport or FieldValidatorSupport, and configure in validators.xml

${actionBean} attribute

ValueStack

Implementations of TypeConverter<T> (generified)

Implementations of ognl.TypeConverter, typically extensions ofStrutsTypeConverter (not generified)

Implementations of Formatter<T> (generified)

Implementations of ognl.TypeConverter, typically extensions ofStrutsTypeConverter (not generified)

Automatically loaded with Extension.Packages init-parameter

Configuration in struts.xml

Implementations of Interceptor, or methods annotated with@Before/@After

Implementations of Interceptor, with configuration in struts.xml

Resource bundle(s) for errors and field names, and JSTL

Resource bundle search mechanism

Actions

Stripes actions are defined by classes that implement the ActionBean interface, and are automatically loaded by being in one of the packages or subpackages of the packages listed in the ActionResolver.Packages initialization parameter.

Struts2 actions can be plain classes that have a public String execute() method, or classes that implement the Action interface. They must be declared instruts.xml, or automatically loaded with a mechanism copied from inspired by Stripes.

Event handlers

In Stripes, methods of the signature public Resolution methodName() in an action bean define event handlers. Using name= in submit buttons and event= in links with the name of the method targets that method when the action is triggered. Having more than one event handler, and more than one submit button in a form, is simply a matter of defining multiple event handlers and putting the corresponding name in the tag of the submit button.

Struts2 is geared towards having a single event handler method, execute(). You can have other event handler methods with arbitrary names, but you must configure a strategy in struts.xml for mapping a URL to a method name.

Struts2 makes it surprisingly difficult to have more than one submit button in a form. It's doable, but not in as straightforward a manner as in Stripes, as can be seen here.

Resolutions vs. Results

Stripes event handlers return implementations of the Resolution interface. Stripes comes with built-in implementations to forward or redirect a request, stream data, return a JavaScript object, or return an HTTP error code. It's very simple to implement the Resolution interface (it has just one method) to suit custom requirements.

Struts2's execute() methods return a String, which is a symbolic result which must then be mapped to something concrete, either in struts.xml or with an annotation. Arguably, returning a symbolic result and having to go off somewhere else to link the string to a result is an unnecessary burden on the developer. Tim discusses this topic in more detail here.

Custom Type Converters

With Stripes, writing a custom type converter involves implementing the TypeConverter<T> interface, where T is the target type. Then, you can use the type converter for every property of type T simply by putting the type converter in an Extension.Packages package. Alternatively, you can use the type converter for specific properties only by annotating the target property with @Validate(converter=YourTypeConverter.class).

With Struts2, you write a custom type converter by implementing the ognl.TypeConverter interface, usually by extending the StrutsTypeConverter class. Contrary to Stripes, the Struts2 interface is not generified, so your method will return an Object. To use the type converter for every property of type T, you add a line toxwork-conversion.properties with the property being the fully qualified name of T, and the value being the fully qualified class name of your type converter. For a specific property, you add the name of the property and the fully qualified class name of your type converter in ActionName-conversion.properties whereActionName is the class name of the action, and the file is in the same directory hierarchy as the package of the action class.

View Technology

The Stripes framework supports any view technology that supports JSP tag libraries. This means you can use JSP and Freemarker, as both can be implemented as a servlet mapping. JSP is available from J2EE, FreeMarker has to be configured as detailed in FreeMarker with Stripes. Using Velocity with Stripes is possible using the tools project VelocityView, but you will miss the taglib support. Velocity 1.5 doesn't support JSP taglibs – this is a feature on the 2.0 wishlist since 2006.

With Struts2, JSP is supported just like with Stripes. But Struts2 also has plugins to handle both Freemarker and Velocity, thus enabling it's functionality for both these view technologies. That being said, using Freemarker (or JSP) is somewhat more natural than Velocity. For example, for this markup:

<s:form action="Login">
<s:textfield name="username" label="Username"/>
<s:submit value="Submit"/>
</s:form>

The Velocity equivalent is:

#sform ("action=Login")
#stextfield ("name=username" "label=Username")
#ssubmit ("value=Submit")
#end

Interceptors

Interceptors in Stripes are classes that implement the Interceptor interface and specify the lifecycle stage(s) to be intercepted with the @Intercepts annotation. Stripes will automatically load the class via the Extension.Packages mechanism. You can also configure interceptors in web.xml if the order in which interceptors are executed is important.

Struts2 interceptors also implement an Interceptor interface. You must then define the interceptor class in struts.xml, and define a new interceptor stack that uses the default stack and adds your interceptor. Finally, you have to configure which actions will use this new interceptor stack.

 摘自:https://stripesframework.atlassian.net/wiki/display/STRIPES/Stripes+vs.+Struts2
分享到:
评论

相关推荐

    Java Web层框架之比较—比较JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket.doc

    Java Web层框架之比较—比较JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket.doc

    stripes快速入门教程

    和我们熟悉 Struts 1 和 Struts 2 类似,Stripes 同样是一种展示层框架,用于快速构建web程序。在使 用Struts 1,WebWork 和 Struts 2 等框架的时候,通常需要大量额外的 XML 配置,当一个项目达到 一定规模的的时候...

    stripes英文文档(全部)

    和我们熟悉 Struts 1 和 Struts 2 类似,Stripes 同样是一种展示层框架,用于快速构建web程序。在使用Struts 1,WebWork 和 Struts 2 等框架的时候,通常需要大量额外的 XML 配置,当一个项目达到一定规模的的时候,...

    stripes入门

    stripes入门,Stripes是一个以让程序员的web开发简单而高效为准则来设计的基于动作的开源Java web框架。本文将介绍Stripes与其它如Struts之类基于动作的框架的区别和其提供的一些存在于Ruby on Rails之中的简单性。

    Stripes视图框架demo

    Stripes视图框架demo 资源可用性毋庸置疑 下载的童鞋给点辛苦分不要介意

    在Stripes中下载excel表格

    Stripes是一种新的简易的web框架势,本篇介绍在Stripes中下载excel表格

    stripes framework

    Make developing web applications in Java easy...Make the Stripes ramp up time for a new developer less than 30 minutes Make it really easy to extend Stripes, without making you configure every last thing

    Stripes 快速入门 pdf 中文版 下载

    Stripes 快速入门 pdf 中文版 下载

    Stripes使用Ajax

    Stripes是一种新的Web框架,比struts2更简单项式,Stripes使用Ajax

    stripes+spring+mybatis框架

    stripes1.5.7+spring3.1.1+MyBatis3.1.1完整框架 本工程代码已完成了Oracle,MySQL,MSSQL2005三种数据库物理分页方言,并测试可用。 本代码集成了xheditor-1.2.1在线编辑器远程抓取图片功能。 集成了excel导入...

    《stripts-documentation-1.4.2》

    Struts的 is pretty feature-light and has some serious architectural issues (see Stripes vs. Struts for details).相当的功能,并已根据一些严重的建筑设计问题(见条纹与Struts的详情) 。 Others, like ...

    Stripes by Example(Apress,2015)

    In this 100-page book, you will find that Stripes provides a very simple learning path, where you do not need to understand the entire framework in order to use it. The concept of this book is exactly...

    stripes 和css 一些常用功能

    NULL 博文链接:https://rainyear.iteye.com/blog/1539513

    Wordpress Blue Stripes模板

    Wordpress Blue Stripes模板

    Wordpress Neon Stripes模板

    Wordpress Neon Stripes模板

    轻量级mvc框架之:stripes (一、约定大于配置)

    NULL 博文链接:https://jayung.iteye.com/blog/1882363

    SQL Stripes 2.8.0.900

    SQL Stripes 2.8.0.900

    stripes:用于构建前端FOLIO模块的UI框架

    背景-Stripes框架包的简要概述-指导条纹设计的概念-与条带有关的事物的术语条纹显影入门和新环境设置-更详细的概述 World-使用Stripes CLI为FOLIO创建一个hello world应用程序开发和测试指南-如何将现有应用程序迁移...

    platform-complete:FOLIO的全套Stripes模块

    它仅由一个NPM 指定,该版本指定@folio/stripes-core的版本以及希望作为此平台的一部分提供的任何Stripes模块,以生成客户端捆绑包,以及用于为每个Stripes生成模块描述符的实用程序模块。 请参阅以获取更多信息。...

Global site tag (gtag.js) - Google Analytics