- 浏览: 511417 次
- 性别:
- 来自: 深圳
最新评论
-
di1984HIT:
学习了~~
jackson JSON对象映射出多余字段的bug -
lvye351:
当然,在tomcat还有JPDA这种方式 ,来远程debug: ...
配置linux下tomcat的远程debug -
hety163:
好,语言简单明了易懂
Http和Socket连接区别 -
高军威:
<b>行不行</b>
XSS转码 && struts2 property标签的bug -
chjy1983:
请教下,我这样:JSONObject jsonObject = ...
HttpClient4 POST数据及问题
“XWork 2 is a generic command pattern framework. It forms the core of Struts 2 .”
~xwork2 是struts2 的核心!!!是基于命令模式的一个框架。其实要看懂xwork基本就不需要看struts2了、
个人理解的xwork,核心就是代理模式+AOP的拦截器, 命令模式实现,线程变量类!
Xwork is a command pattern framework centralized around an Action interface. You define action classes by implementing an Action interface, then XWork will setup and execute your actions. XWork is most widely known from the web MVC framework called Webwork. However, XWork can be used by itself, so its important to understand the XWork layers and how actions are set up and executed. This section describes the core layers within Xwork and provides a simple example of how to execute actions.
~~Xwork是以Action接口为中心的命令模式实现框架。定义一个Action的实现类,然后Xwork将装配并执行它。其核心接口如下:
- Action Interface
- ActionProxy interface
- ActionInvocation interface
- ActionContext
- A simple example
Actions
Actions are classes that get invoked in response to a request, execute some code and return a Result. Actions implement at a minimum a single method, execute(), that defines the entry point called by the framework. This method allows developers to define a unit of work that will be executed each time the Action is called.
~Action是响应请求、执行定义的操作、返回一个结果对象的类。其核心方法只有一个,就是execute(),这个方法是框架执行方法的入口。
ActionContext
The ActionContext provides access to the execution environment in the form of named objects during an Action invocation. A new ActionContext is created for each invocation allowing developers to access/modify these properties in a thread safe manner. The ActionContext makes a number of properties available that are typically set to appropriate values by the framework. In WebWork 2 for example, the ActionContext session map wraps an underlying HttpSession object. This allows access to environment specific properties without tying the core framework to a specific execution environment. For more information, see ActionContext in Basics.
~~ActionContext类,可以使得Action在调用时,通过其获取到执行环境中变量的,并且是线程安全的方式!在WebWork2中,ActionContext的sessionmap变量中就包装了HttpSession对象的值,这样就可以在action调用的过程中获取到环境变量值。
Interceptors
In XWork, Interceptors are objects that dynamically intercept Action invocations. They provide the developer with the opportunity to define code that can be executed before and/or after the execution of an action. They also have the ability to prevent an action from executing. Interceptors provide developers a way to encapulate common functionality in a re-usable form that can be applied to one or more Actions. See Interceptors for further details.
~~ 拦截器,before/after类型,没有环绕型的:) 拦截器可以组成链,使得一个Action调用经过顺序的拦截器 。
Stacks
To handle the case where developers want to apply more than a single Interceptor to an Action, Stacks have been introduced. Stacks are an ordered list of Interceptors and/or other Stacks that get applied when an Action is invoked. Stacks centralize the declaration of Interceptors and provide a convenient way to configure mutiple actions.
~~栈在xwork中,主要是用来描述多个拦截器顺序执行的一个概念。
Results
Results are string constants that Actions return to indicate the status of an Action execution. A standard set of Results are defined by default: error, input, login, none and success. Developers are, of course, free to create their own Results to indicate more application specific cases.
~~~定义了Action执行后的返回。即命令模式的出口
Result Types
Result Types are classes that determine what happens after an Action executes and a Result is returned. Developers are free to create their own Result Types according to the needs of their application or environment. In WebWork 2 for example, Servlet and Velocity Result Types have been created to handle rendering views in web applications.
Packages
Packages are a way to group Actions, Results, Result Types, Interceptors and Stacks into a logical unit that shares a common configuration. Packages are similiar to objects in that they can be extended and have individual parts overridden by "sub" packages.
ValueStack
The ValueStack is a stack implementation built on top of an OGNL core. The OGNL expression language can be used to traverse the stack and retrieve the desired object. The OGNL expression language provides a number of additional features including: automatic type conversion, method invocation and object comparisons. For more information, see the OGNL Website .
~stack模式的变量堆栈。struts2与页面之间的变量赋值,其实就是这个特性。支持OGNL。
Components
XWork provides the ComponentManager interface (and a corresponding implementation in the DefaultComponentManager class) to apply a design pattern known as Inversion of Control (or IoC for short). In a nutshell, the IoC pattern allows a parent object (in this case XWork's ComponentManager instance) to control a client object (usually an action, but it could be any object that implements the appropriate enabler ). See Components for further details.
~~对象管理组件,不过IOC通常推荐spring来代替,这里值得一看的还是ActionProxyFactory这个工厂类。
下面就是一组代码了,通过定义一个Action,创建并执行的过程,就可以清楚的了解到整个框架的运作过程:
1.定义action
public class ViewBookAction implements Action{ Book book; String id; public String execute() throws Exception{ // lets pretend we have a data access object that will return a book from storage book = bookDAO.findById(id, Book.class); if(book != null) return "success"; return "notFound"; } public Book getBook(){ return this.book; } public setId(String id){this.id = id; } }
2.定义环境变量(ActionContext.),工厂方法构建ActionProxy(Action的代理),然后代理获取Action实例,执行。
// obtain inputs from the caller. For this example, we can just define some dummy params. Map paramMap = new HashMap(); paramMap.put("id", "0123456789"); // set the ActionContext parameters Map context = new HashMap(); context.put(ActionContext.PARAMETERS, paramMap); // create an action proxy with no namespace, action alias (defined in xwork.xml), and a map of the context info ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("","viewBook", context); // we have the action proxy instance, lets execute it and retrieve the action String result = proxy.execute(); if ("success".equals(result)){ ViewBookAction action = (ViewBookAction) proxy.getAction(); // return info back to caller or just print to screen for this example System.out.println(action.getBook().getTitle()); } else if("notFound".equals(result){ // forward to another inventory source } else { throw new RuntimeException("Im lazy"); }
3.简单的配置文件。是不是很熟悉呢。。struts2基本就是抄这里了
<xwork> <include file="xwork-default.xml"/> <package name="default" extends="xwork-default"> <action name="viewBook" class="com.opensymphony.xwork.example.ViewBookAction"/> </package> </xwork>
最后来一张总图:
发表评论
-
Nginx rewrite permanent
2014-03-19 16:43 1764fpm之后,尝试兼容url错误的一段redirect失效。具 ... -
ZmEu漏洞扫描
2014-02-21 16:59 7478挺黑的,nginx抓出来的日志。扫描各种php软件、数据库 ... -
Continuous Integration with Xcode 5
2014-01-09 15:04 996xcode5 及持续集成, 花了20分钟上手配置, 效果非 ... -
Httpclient4.3实例。 每个版本接口变更都巨大
2014-01-08 17:55 33531.新增简单的url请求内容返回, 比较时髦的链调用 ... -
nginx proxy_http_version
2014-01-07 16:10 6375nginx转 apache ,发现HTTP协议版本 从1.1 ... -
ubuntu一键升级到13.10的教训
2013-12-16 11:51 1106从13.04升级到13.10,主要两个变化非常蛋疼: 1 ... -
【PHP】Codeigniter : Unable to locate the model you have specified
2013-12-10 11:36 1916产生这个问题一般两个原因: 1. google到的结果,类 ... -
springMVC + jsonP
2013-11-20 12:58 4198/** * 根据分类id,取新闻列表 ... -
PC端 浏览器Agent切换工具
2013-11-18 11:04 1057插件比较方便,技术流还是推荐fiddler -
Spring3.x中的几个异步执行
2013-08-22 15:00 29041.servlet3 细节可以阅读http://www.i ... -
Mybatis Cache探究
2013-08-22 12:01 1983这里先不讨论第三方的cache集成(有memcach ... -
spring3-基于注解的AOP
2013-08-02 11:58 1044要点: 1.aop的概念真的很多。。。其实从使用出发无非 ... -
HttpClient4 POST数据及问题
2012-05-23 18:03 33600post 方式挂参数的三种格式, mark一下。 ... -
struts2-ognl mark
2011-12-29 16:49 1580暂时mark在这,后面再补充 1. 关于漏洞的问 ... -
类模板语言的变量替换~简易java实现
2011-04-06 15:25 3722场景1:数据库存有 xx,y ... -
XSS转码 && struts2 property标签的bug
2011-03-25 15:36 6683一。了解背景 下面两张图,比较html转义和js的转义。 ... -
小折腾一下swing
2011-03-23 16:23 1214近来看美剧《Lost》,可惜下载的rm文件名太长,很难找到自己 ... -
FileUploadInterceptor ~mark陷阱
2011-03-17 15:45 165503/17 14:25:40 [ERRO ... -
新浪微博技术架构分析-转载
2011-03-07 17:07 2135中国首届微博开发者大会在北京举行,这是国内微博行业的首场技术盛 ... -
谨慎使用SocketChannel的read方法
2011-01-13 18:02 6047下面的代码是一个实例化SocketChannel的过程: ...
相关推荐
xwork-1.1.1.jar, xwork-1.1.jar, xwork-1.2.1.jar, xwork-1.2.3.jar, xwork-2.0.0.jar, xwork-2.0.1.jar, xwork-2.0.3.jar, xwork-2.0.4.jar, xwork-2.0.5.jar, xwork-2.0.6.jar, xwork-2.0.7.jar, xwork-2.1.0.jar...
xwork-2.1.5.jar包含了整个框架的功能,而xwork-core-2.1.6.jar则是核心模块,包含Action、Interceptor等关键组件。 7. **与Struts2的关系**: XWork与Struts2紧密相关,Struts2是基于XWork构建的一个MVC框架,它...
《深入解析xwork-core-2.3.4.1源代码》 xwork-core是Struts2框架的核心组件,它提供了Action、Interceptor、ValueStack等关键功能,是理解Struts2工作原理的重要部分。源代码的分析能让我们更深入地了解这个框架的...
用于解决struts2升级至2.3.37时 出现java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.put(Ljava/lang/异常时,更换的xwork-core-2.3.37.jar
xwork-core-2.3.15.1.jar
`xwork-2.1.5`是XWork的一个特定版本,可能包含了一些新特性、性能优化和已知问题的修复。随着Struts2的更新,XWork也会相应升级以保持兼容性并提供更完善的功能。 总之,XWork jar包是构建基于Struts2的Web应用...
xwork-core-2.2.1.1.jar
JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源代码 xwork-2.0.4JavaEE源...
xwork-core-2.3.16.1.jar,欢迎大家下载。
《深入解析xwork-core-2.2.1-sources》 xwork-core是Struts2框架的核心组件之一,它在Web应用开发中扮演着至关重要的角色。本文将深入探讨xwork-core-2.2.1-sources中的核心概念、功能以及源代码分析,帮助开发者更...
《深入剖析xwork-assembly-2.1.6-src:揭秘源码的奥秘》 在软件开发领域,源码是理解系统运作机制的关键。"xwork-assembly-2.1.6-src"是一个开放源码的项目,它为我们提供了深入了解xwork框架核心功能的机会。这个...
xwork-core-2.1.6.jar这个版本才内含StringUtils.class这个工具类,我已经将这个类添加到xwork-core-2.3.34.jar内了。
修正Eclipse中启动JBoss时,提示:Could not create JarEntryRevision for……。 Struts2 2.2.1.2中xwork-core修正包xwork-core-2.2.1.2-SNAPSHOT。
这个压缩包"**xwork-2.1.2.rar**"包含了XWork框架的版本2.1.2,它是Struts2的重要组成部分。 **XWork核心组件详解:** 1. **动作调度(ActionInvocation)**:XWork通过ActionInvocation负责调用和管理Action的生命...
在没有联网的请求本地添加验证xml文件,添加验证XML文件的DTD
《深入解析xwork-2.0.6源码:打造高效Struts2应用》 xwork-2.0.6-src是Struts2框架的核心组件之一,它包含了xwork库的源代码,对于理解Struts2的工作原理以及进行二次开发具有重要的参考价值。本文将深入探讨xwork-...
《深入解析xwork-core源码:为Struts学习铺路》 在Java Web开发领域,Struts框架无疑占据着重要的地位。而xwork-core作为Struts2的核心组件,它的源码解析对于理解Struts的工作机制至关重要。本文将深入探讨xwork-...
《XWork核心库详解——基于xwork-core-2.2.1.1.zip》 XWork,作为Struts2框架的重要组成部分,为Java Web开发提供了强大的动作调度和业务逻辑处理能力。本文将深入探讨xwork-core-2.2.1.1.zip这个压缩包中的核心...
xwork-core-2.3.31
《深入剖析xwork-core-source-2.3.1.2:构建Struts2核心基石》 xwork-core-source-2.3.1.2是Struts2框架的核心库,其源代码提供了对Struts2底层机制的深入了解。Struts2作为一款广泛应用的Java Web MVC框架,xwork-...