WebWork简介

WebWork是由OpenSymphony组织开发的,致力于组件化和代码重用的拉出式MVC模式J2EE Web框架。WebWork目前最新版本是2.2.7,现在的WebWork2.x前身是Rickard Oberg开发的WebWork,但现在WebWork已经被拆分成了Xwork1和WebWork2两个项目。 Xwork简洁、灵活功能强大,它是一个标准的Command模式实现,并且完全从web层脱离出来。 Xwork提供了很多核心功能:前端拦截机(interceptor),运行时表单属性验证,类型转换,强大的表达式语言(OGNL – the Object Graph Notation Language),IoC(Inversion of Control倒置控制)容器等。 WebWork2建立在Xwork之上,处理HTTP的响应和请求。WebWork2使用ServletDispatcher将HTTP请求的变成Action(业务层Action类), session(会话)application(应用程序)范围的映射,request请求参数映射。WebWork2支持多视图表示,视图部分可以使用JSP, Velocity, FreeMarker, JasperReports,XML等。在WebWork2.2中添加了对AJAX的支持,这支持是构建在DWR与Dojo这两个框架的基础之上.【EclipseWork:用于WebWork辅助开发的一个Eclipse插件】

WebWork架构
XWork是一个命令行模式框架,它是WebWork的基础。WebWork在XWork之上添加了一个MVC的Web应用框架。XWork的核心概念包括 Action、Interceptor、Result。WebWork扩展了这些概念的基础实现,用于支持对 Web 应用的开发。

[编辑]Action
WebWork的核心功能是 Action, Action实现了命名模式中的命令对象。

所有 Action 都实现了 com.opensymphony.xwork.Action 接口,该接口只有一个方法:

public String execute() throws Exception
com.opensymphony.xwork.ActionSupport 类实现了 Action 及其其他可选接口,可以作为其他自定义 Action 类的基类。

[编辑]Interceptor
Interceptor可以封装围绕Action执行的代码。包括设置Action属性属性等核心功能在内的大量WebWork特性是以Interceptor方式实现的。WebWork从AOP借鉴了很多拦截器的概念,但两者最大的区别是WebWork不需要任何预处理过程,也不需要修改生成的二进制代码。因为拦截是框架的内部机制,Action调用者及被调用的Action被有效地分隔

[编辑]Result
com.opensymphony.xwork.Result 接口代表 Action 执行后的结果,它只有一个方法

public void execute(ActionInvocation invocation) throws Exception
Result可用于生成 action 执行完毕后需要输出结果,如 Servlet转发、Servlet重定向、Velocity、FreeMaker、JasperReports(PDF, CSV, XML等)、XSLT渲染、ActionChainResult(可用于从当前动作到其他动作的链式处理)

[编辑]OGNL
堆栈是驱动 XWork 和 WebWork 动态上下文的中心,这个堆栈保存了与 Action 运行相关的众多对象,它通过解析表达式动态获取属性值,会从堆栈的头开始包含该属性名称的第一个对象。堆栈建立在OGNL之上

OGNL 能够通过计算表达式定位 JavaBean的属性。

http://www.opensymphony.com/ognl

[编辑]ActionProxy/ActionInvocation
框架把Action执行以ActionProxy/ActionInvocation序对方式封装起来,以便添加核心服务。

ActionProxy是客户端代码执行 Action 的句柄,因为使用代理而不是直接操作对象本身,所以可以在代理中封装 Interceptor, Result 等的额外代码。

ActionProxy实例是ServletDispatcher使用静态ActionProxyFactory实例创建的。ServletDispatcher映射HTTP请求得到一个名字空间和动作别名。动作别名被ActionProxyFactory用于创建正确的ActionProxy。然后 ServletDispatcher 执行 ActionProxy,而 ActionProxy控制着Interceptor, Action和Result的执行.

[编辑]ActionContext
ActionContext 实际上是 ThreadLocal Map

在Action执行期间,Action、Interceptor和Result能访问一个ThreadLocal存储空间: ActionContext, 由ActionProxy管理,并且仅在执行ActionProxy.execute()方法时有效

[编辑]ServletDispatcher
ServletDispatcher是连接WebWork各个部分的胶水,ServletDispatcher通过设置包装了应用域、会话域和参数域属性的 java.util.Map 实现来创建执行动作的上下文环境。随即用 ActinProxyFactory创建ActionProxy, ServletDispatcher执行ActionProxy。ActionProxy 的执行过程包括执行所有相关 Interceptor、Action 本身,根据 Action 返回码找到对应 Result。

[编辑]基本特色
A flexible Validation framework allowing you to decouple validation rules from your action code.
Type Conversion allowing you to easily convert objects from one class to another, solving one of the most tedious efforts when creating web apps.
A powerful Expression Language based on OGNL allowing dynamic object graph traversal and method execution and transparent access to properties from multiple beans using a ValueStack. Webwork also has the ability to use JSTL.
Inversion of Control integration that manages component lifecycle and dependencies without the need to build registry classes that clients must call to obtain a component instance. WebWork recommends Spring for IoC.
Reusable Tags that allow for easy and reusable component-oriented web development using Themes and Templates
Advanced Interceptors that provide for various rich functionality, including preventing multiple form submissions and executing long running queries in the background.
Hierarchical and pluggable support for Internationalization.
Easy integration with third party software including Hibernate, Spring, Sitemesh, and JSTL.
Support for many view technologies such as JSP, FreeMarker, and JasperReports.
Modular Configuration Files using packages and namespaces to manage hundreds of actions.
Advanced AJAX features provided by the ajax theme.
[编辑]HelloWorld
HellowWorld.java

package com.acme.action;          
import com.opensymphony.xwork.ActionSupport;
public class HelloWorld extends ActionSupport {
   private String message;
   public String execute() {
     message = "Hello World!";
     return SUCCESS;
   }
   public String getMessage() {
     return message;
   }
}
index.jsp

<%@page contentType="text/html"%>
<%@taglib prefix="ww" uri="/webwork"%>
<%@page pageEncoding="UTF-8"%>
<html><body>
<ww:property value="message"/>
</body></html>
xwork.xml

<action name="HelloWorld" class="com.acme.action.HelloWorld">
     <result name="success" type="dispatcher">/index.jsp</result>
</action>
context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/HelloWebWork"/>
run example

http://localhost:8084/HelloWebWork/HelloWorld.action
More Detail: http://www.netbeans.org/kb/55/quickstart-webwork-in-netbeans.html

你可能感兴趣的:(spring,Ajax,框架,Webwork,Netbeans)