Stripes vs struts2

这篇文章对比了Strides和Struts2之间的关键差异,包括版本、配置、响应机制、视图技术、布局机制、绑定机制、验证、模型到视图的数据传输、类型转换、格式化、自定义模块配置、拦截器、本地化、事件处理器、解决方案与结果、自定义类型转换器、视图技术、拦截器、类型转换和视图技术。
 
Skip to end of metadata
 
Go to start of metadata
 

Here are some quick comparison points between Stripes and Struts2:

 

Stripes

Struts2

Version

1.5

2.0.12

Configuration

web.xml

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

Main workhorse

Classes that implement ActionBean

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

Response mechanism

Instance of Resolution

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

View technology

JSP or FreeMarker

JSP, FreeMarker, or Velocity

Layout mechanism

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

Tiles or SiteMesh

Binding mechanism

Built-in

OGNL

Validation

@Validate and @ValidateNestedProperties

Configure in an XML file, or use annotations

Validation short-circuiting

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

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

Custom validation

Annotate your method with @ValidationMethod

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

Model-to-view data transfer

${actionBean} attribute

ValueStack

Type conversion

Implementations of TypeConverter<T> (generified)

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

Formatting

Implementations of Formatter<T> (generified)

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

Custom module configuration

Automatically loaded with Extension.Packages init-parameter

Configuration in struts.xml

Interceptors

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

Implementations of Interceptor, with configuration in struts.xml

Localization

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
第三方支付功能的技术人员;尤其适合从事电商、在线教育、SaaS类项目开发的工程师。; 使用场景及目标:① 实现微信与支付宝的Native、网页/APP等主流支付方式接入;② 掌握支付过程中关键的安全机制如签名验签、证书管理与敏感信息保护;③ 构建完整的支付闭环,包括下单、支付、异步通知、订单状态更新、退款与对账功能;④ 通过定时任务处理内容支付超时与概要状态不一致问题:本文详细讲解了Java,提升系统健壮性。; 阅读应用接入支付宝和建议:建议结合官方文档与沙微信支付的全流程,涵盖支付产品介绍、开发环境搭建箱环境边学边练,重点关注、安全机制、配置管理、签名核心API调用及验签逻辑、异步通知的幂等处理实际代码实现。重点与异常边界情况;包括商户号与AppID获取、API注意生产环境中的密密钥与证书配置钥安全与接口调用频率控制、使用官方SDK进行支付。下单、异步通知处理、订单查询、退款、账单下载等功能,并深入解析签名与验签、加密解密、内网穿透等关键技术环节,帮助开发者构建安全可靠的支付系统。; 适合人群:具备一定Java开发基础,熟悉Spring框架和HTTP协议,有1-3年工作经验的后端研发人员或希望快速掌握第三方支付集成的开发者。; 使用场景及目标:① 实现微信支付Native模式与支付宝PC网页支付的接入;② 掌握支付过程中核心的安全机制如签名验签、证书管理、敏感数据加密;③ 处理支付结果异步通知、订单状态核对、定时任务补偿、退款及对账等生产级功能; 阅读建议:建议结合文档中的代码示例与官方API文档同步实践,重点关注支付流程的状态一致性控制、幂等性处理和异常边界情况,建议在沙箱环境中完成全流程测试后再上线。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值