`
zhb8015
  • 浏览: 397376 次
  • 性别: 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
分享到:
评论

相关推荐

    Stripes 快速入门 pdf 中文版 下载

    Stripes vs Struts 2 - **配置方式**:虽然Struts 2也支持注解配置,但在很多情况下仍然需要使用XML配置文件。相比之下,Stripes更倾向于使用注解来简化配置。 - **性能**:由于Stripes减少了对中间层(如拦截器)...

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

    本文将深入对比六种流行的Java Web层框架:JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket。 **JavaServer Faces (JSF)** JSF作为Java EE的一部分,拥有广泛的支持和市场需求。它的优点在于快速上手和丰富...

    stripes快速入门教程

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

    stripes英文文档(全部)

    在介绍Stripes之前,我们需要了解它与传统框架(如 Struts 1、WebWork 和 Struts 2)的不同之处。传统框架通常要求开发者编写大量的XML配置文件以实现应用的配置和管理,这不仅增加了开发者的负担,而且当项目规模...

    Stripes视图框架demo

    6. **Servlet集成**:Stripes是一个Servlet过滤器,可以与其他Servlet框架如Spring、Struts等无缝集成,扩展性强。 7. **国际化和本地化**:Stripes内置了对多语言的支持,方便创建面向全球用户的Web应用。 8. **...

    stripes入门

    1. **配置方式**:Struts 使用 XML 文件进行配置,而 Stripes 则主要依赖于注解和约定,这使得 Stripes 在配置方面更为简洁。 2. **表单处理**:Stripes 提供了一套强大的表单处理机制,能够自动处理表单数据绑定、...

    stripes 和css 一些常用功能

    与传统的框架如Struts1和Struts2相比,Stripes有自己独特的优势。首先,Stripes提倡“约定优于配置”的开发原则,这意味着它尽量减少了XML配置的使用,而更侧重于Java代码中的注解(Annotations)。这样一来,开发者...

    在Stripes中下载excel表格

    相较于其他Java Web框架如Spring MVC或Struts,Stripes框架更加强调简洁性和易用性。它通过提供一系列简洁明了的API来帮助开发者快速构建高性能的Web应用。 #### 二、Stripes中的文件下载机制 在Stripes框架中,...

    Maven+jetty+jrebel+m2eclipse+eclipse搭建struts2开发环境

    至于"stripes",这可能是Struts2的一个子项目或者模块,但没有足够的信息来具体解释它的含义。通常,Stripes是一个轻量级的Java Web框架,与Struts2类似,用于构建动态Web应用。如果在描述中提到的压缩包包含...

    jsp网页布局利器框架stripes-1.5.6

    2. "stripes-1.5.6" - 这可能是框架的源码、库文件或者二进制发行版,供开发者集成到他们的项目中。通常包含类库、文档、示例应用等资源。 使用Stripes框架,开发者可以利用ActionBean(控制器)、事件驱动模型和...

    Spring集成Struts、JSF、WebWork2

    3. **WebWork2**(WebWork前身,后来演变为现在的Stripes框架):WebWork强调轻量级和可扩展性,它的Action系统比Struts更加灵活。WebWork2引入了拦截器(Interceptor)的概念,使得AOP(面向切面编程)更容易实现。...

    Stripes使用Ajax

    与Struts2相比,Stripes更加简洁明了,其设计原则更加倾向于简单实用。 #### 二、Stripes框架中的Ajax应用 Ajax(Asynchronous JavaScript and XML)是一种创建交互式网页应用程序的技术。通过Ajax,网页可以在不...

    《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 ...

    Matt Raible对各种Java Web层比较

    在Matt Raible的分享中,他对比分析了几种流行的Java Web层框架,包括JSF、Spring MVC、Stripes、Struts2、Tapestry和Wicket。 #### 三、各框架优缺点分析 1. **JSF (JavaServer Faces)** - **优点**: - Java ...

    Java Web层框架比较.docx

    以下是关于JSF、Spring MVC、Stripes、Struts 2、Tapestry和Wicket的详细比较: 1. **JavaServer Faces (JSF)** - **优点**:作为Java EE的一部分,JSF具有广泛的支持和应用,意味着更多的就业机会。它的学习曲线...

    基于SSH的WEB开发

    例如,JSF、Spring MVC、Stripes、Struts2.0、Tapestry和Wicket都是Struts1.x的替代方案,它们各有特点,适应不同的开发场景。 总的来说,基于SSH的Web开发提供了一种高效、灵活的解决方案,它通过Struts实现MVC...

    JAVA框架对比(author:Matt raible)

    描述:本资源由Matt Raible提供,深入比较了六个主要的Java Web框架:JSF、Spring MVC、Stripes、Struts2、Tapestry和Wicket,旨在帮助开发者根据项目需求选择最适合的框架。 知识点: 1. **JSF (JavaServer Faces...

    基于SSH的web开发

    在Web显示层框架的选择上,有多种选项如JSF、Spring MVC、Stripes、Struts1.x、Struts2.0、Tapestry、Wicket、Flex、GWT、Seam、Ext等。选择哪个框架取决于项目的特性,如是否需要富客户端交互、对Ajax的支持程度、...

Global site tag (gtag.js) - Google Analytics