- 浏览: 418660 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (244)
- struts2 (15)
- ognl (1)
- hibernate (17)
- gwt (17)
- GROOVY (2)
- GRAILS学习 (7)
- SPRING (4)
- AJAX (2)
- JQUERY (6)
- XML (1)
- DWR (3)
- 线程 (0)
- SVN (0)
- json (1)
- anotation (0)
- 反射 (2)
- rapidframework (0)
- OA工作流 (2)
- 事务 (0)
- mysql (0)
- oracle (26)
- EXTJ (0)
- 求职 (2)
- 随笔 (22)
- 注释 (1)
- java综合 (30)
- 设计模式 (1)
- JSP SERVLET (2)
- 插件 (7)
- 应用 (3)
- HTML (5)
- flex (13)
- android (8)
- javascript (14)
- Exception (0)
- Linux (2)
- 计算机常识 (3)
- EXCEL (2)
- 正则表达式 (1)
- 开源工具 (2)
- 测试 (1)
- 生活 (7)
- 房子 (0)
- 购房大学 (4)
- UML (1)
- 服务器 (1)
- 发展 (1)
- 英语 (1)
- 项目管理 (1)
- 摘 (1)
- 网站 (1)
最新评论
-
a347911:
架构师教程:https://note.youdao.com/s ...
架构师之路--- 一个四年 JAVA 程序员的工作经历 转 -
hzxlb910:
对我帮助很大。
架构师之路--- 一个四年 JAVA 程序员的工作经历 转 -
xly_971223:
引用因此,while (!isInterrupted())也可 ...
Java 终止线程方法 -
zdglt88:
其实这个datagrid挺简单的,没有难度
Jquery easy ui 之datagrid简介 -
完善自我:
抓住重点,支持一下!
Jquery easy ui 之datagrid简介
com.opensymphony.webwork下有两个类:public class ServletActionContext extends ActionContext implements WebWorkStatics;
这个类是静态工具类,其内的方法均依赖com.opensymphony.xwork.ActionContext类,而这个类提供了Action类的执行上下文.我们跟踪这个上下文的生命周期:
客户请求发送到Webserver,它将请求转发到Servlet容器,容器匹配一个Sertlet,然后调用其sevice()方法.在WebWork中这个servlet是ServletDispatcher,其中的serviceAction方法通过代理模式从WebWork进入到XWork对象世界,在那里对客户请求数据对象执行处理,通过执行根据配置上下文和执行上下文设置的Action和result把响应数据发回客户端,发回的动作可能发生在Result中,也可能发生在Interceptor中.开始代码之旅.
下面是serviceAction代码:
public void serviceAction(HttpServletRequest request, HttpServletResponse response, String namespace, String actionName, Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap) {
HashMap extraContext = createContextMap(requestMap, parameterMap, sessionMap, applicationMap, request, response, getServletConfig());
extraContext.put(SERVLET_DISPATCHER, this);
// If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
OgnlValueStack stack = (OgnlValueStack) request.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY);
if (stack != null) {
extraContext.put(ActionContext.VALUE_STACK,new OgnlValueStack(stack));
}
try {
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
proxy.execute();
// If there was a previous value stack then set it back onto the request
if (stack != null){
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,stack);
}
} catch (ConfigurationException e) {
log.error("Could not find action", e);
sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
log.error("Could not execute action", e);
sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
方法createContextMap执行数据的包装:
public static HashMap createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, HttpServletRequest request, HttpServletResponse response, ServletConfig servletConfig) {
HashMap extraContext = new HashMap();
extraContext.put(ActionContext.PARAMETERS, parameterMap);
extraContext.put(ActionContext.SESSION, sessionMap);
extraContext.put(ActionContext.APPLICATION, applicationMap);
extraContext.put(ActionContext.LOCALE, (locale == null) ? request.getLocale() : locale);
extraContext.put(HTTP_REQUEST, request);
extraContext.put(HTTP_RESPONSE, response);
extraContext.put(SERVLET_CONFIG, servletConfig);
extraContext.put(ComponentInterceptor.COMPONENT_MANAGER, request.getAttribute(ComponentManager.COMPONENT_MANAGER_KEY));
// helpers to get access to request/session/application scope
extraContext.put("request", requestMap);
extraContext.put("session", sessionMap);
extraContext.put("application", applicationMap);
extraContext.put("parameters", parameterMap);
AttributeMap attrMap = new AttributeMap(extraContext);
extraContext.put("attr", attrMap);
return extraContext;
}
众所周知,不仅WebWork能使用XWork,而且还可以有类似的FtpWork,MailWork,JMSWork能够替代WebWork来使用Xwork,为什么能够这样,因为Xwork的使用方式.在上面的serviceAction方法中:
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
proxy.execute();
这些代码就是这种方式的体现:动作代理-动作调用-具体的动作.为使客户代码不绑定到特定代理,XWork使用了一个工厂模式,提供工厂类 ActionProxyFactory.
方法createActionProxy实际调用导致一个ActionProxy接口的缺省实现DefaultActionProxy被实例化:
它的构造器是:
protected ActionInvocation invocation;
protected DefaultActionProxy(String namespace, String actionName, Map extraContext, boolean executeResult) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating an DefaultActionProxy for namespace " + namespace + " and action name " + actionName);
}
this.actionName = actionName;
this.namespace = namespace;
this.executeResult = executeResult;
this.extraContext = extraContext;
config = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName);
if (config == null) {
String message;
throw new ConfigurationException(message);
}
prepare();
}
protected void prepare() throws Exception {
//创建ActionInvocation 实例化的仍然是由代理工厂类的工厂方法进行,实例化该接口的缺省 实现DefaultActionInvocation.
invocation = ActionProxyFactory.getFactory().createActionInvocation(this, extraContext);
}
下面是proxy.execute()的细节:
public String execute() throws Exception {
ActionContext nestedContext = ActionContext.getContext();
ActionContext.setContext(invocation.getInvocationContext());
String retCode = null;
try {
retCode = invocation.invoke();
} finally {
ActionContext.setContext(nestedContext);
}
return retCode;
}
最后,看看这个类: DefaultActionInvocation类的invoke方法是如何处理extraContext,先看初始化过程,从构造器开始:
protected DefaultActionInvocation(ActionProxy proxy, Map extraContext, boolean pushAction) throws Exception {
this.proxy = proxy;
this.extraContext = extraContext;
this.pushAction = pushAction;
init();
}
方法init定义,把extraContext转换到invocationContext中,并获得拦截器清单.
private void init() throws Exception {
Map contextMap = createContextMap();
createAction();
if (pushAction) {
stack.push(action);
}
invocationContext = new ActionContext(contextMap);
invocationContext.setName(proxy.getActionName());
List interceptorList = new ArrayList(proxy.getConfig().getInterceptors());
interceptors = interceptorList.iterator();
}
在下面这个方法中获得动作上下文contextMap,并把extraContext包含其中.
protected Map createContextMap() {
Map contextMap;
if ((extraContext!=null)&& (extraContext.containsKey(ActionContext.VALUE_STACK))) {
// In case the ValueStack was passed in
stack = (OgnlValueStack) extraContext.get(ActionContext.VALUE_STACK);
if (stack == null) {
throw new IllegalStateException("There was a null Stack set into the extra params.");
}
contextMap = stack.getContext();
} else {
// create the value stack
// this also adds the ValueStack to its context
stack = new OgnlValueStack();
// create the action context
contextMap = stack.getContext();
}
// put extraContext in
if (extraContext != null) {
contextMap.putAll(extraContext);
}
//put this DefaultActionInvocation into the context map
contextMap.put(ActionContext.ACTION_INVOCATION, this);
return contextMap;
}
protected void createAction() {
// load action
try {
action = ObjectFactory.getObjectFactory().buildAction(proxy.getConfig());
} catch (InstantiationException e) {
throw new XworkException("Unable to intantiate Action!", e);
} catch (IllegalAccessException e) {
throw new XworkException("Illegal access to constructor, is it public?", e);
} catch (ClassCastException e) {
throw new XworkException("Action class " + proxy.getConfig().getClassName() + " does not implement " + Action.class.getName(), e);
} catch (Exception e) {
String gripe = "";
if (proxy == null) {
gripe = "Whoa! No ActionProxy instance found in current ActionInvocation. This is bad ... very bad";
} else if (proxy.getConfig() == null) {
gripe = "Sheesh. Where'd that ActionProxy get to? I can't find it in the current ActionInvocation!?";
} else if (proxy.getConfig().getClassName() == null) {
gripe = "No Action defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'";
} else {
gripe = "Unable to instantiate Action, " + proxy.getConfig().getClassName() + ", defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'";
}
gripe += (((" -- " + e.getMessage()) != null) ? e.getMessage() : " [no message in exception]");
throw new XworkException(gripe, e);
}
}
初始化结束了, 接下来看看invocation.invoke()到底做了什么:
public String invoke() throws Exception {
if (executed) {
throw new IllegalStateException("Action has already executed");
}
if (interceptors.hasNext()) {
Interceptor interceptor = (Interceptor) interceptors.next();
在这个类中,并没有调用getResult(),因为这个方法是由某些拦截器调用的,例如: ExecuteAndWaitInterceptor, TokenSessionStoreInterceptor,如果自己需要,也可以创建自己的拦截器,并在其中访问它.
通过Interceptor接口中的String intercept(ActionInvocation invocation) throws Exception可以看到, 参数invocation已经携带了所有能处理的数据了.
resultCode = interceptor.intercept(this);
} else {
resultCode = invokeAction(getAction(), proxy.getConfig());
}
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();
listener.beforeResult(this, resultCode);
}
}
now execute the result, if we're supposed to,如果不期望执行Result,那么在代理中设置proxy.getExecuteResult(false)即可,有时候是需要这样的,如TokenSessionStoreInterceptor;
if (proxy.getExecuteResult()) {
executeResult();
}
executed = true;
}
return resultCode;
}
在这个方法中,调用了Result接口的方法execute(ActionInvocation),当该方法返回时一个请求响应回合就完成了.
private void executeResult() throws Exception {
result = createResult();
if (result != null) {
result.execute(this);
} else if (!Action.NONE.equals(resultCode)) {
LOG.warn("No result defined for action " + getAction().getClass().getName() + " and result " + getResultCode());
}
}
public Result createResult() throws Exception {
Map results = proxy.getConfig().getResults();
ResultConfig resultConfig = (ResultConfig) results.get(resultCode);
Result newResult = null;
if (resultConfig != null) {
try {
newResult = ObjectFactory.getObjectFactory().buildResult(resultConfig);
} catch (Exception e) {
LOG.error("There was an exception while instantiating the result of type " + resultConfig.getClassName(), e);
throw e;
}
}
return newResult;
}
public Result getResult() throws Exception {
Result returnResult = result;
// If we've chained to other Actions, we need to find the last result
while (returnResult instanceof ActionChainResult) {
ActionProxy aProxy = ((ActionChainResult) returnResult).getProxy();
if (aProxy != null) {
Result proxyResult = aProxy.getInvocation().getResult();
if ((proxyResult != null) && (aProxy.getExecuteResult())) {
returnResult = proxyResult;
} else {
break;
}
} else {
break;
}
}
return returnResult;
}
protected String invokeAction(Action action, ActionConfig actionConfig) throws Exception {
if (proxy.getConfig().getMethodName() == null) {
return getAction().execute();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing action method = " + actionConfig.getMethodName());
}
try {
Method method = actionConfig.getMethod(action.getClass());
if (action instanceof Proxy) {
try {
return (String) Proxy.getInvocationHandler(action).invoke(action, method, new Object[0]);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new Exception("Error invoking on proxy: " + throwable.getMessage());
}
} else {
return (String) method.invoke(action, new Object[0]);
}
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Method '" + actionConfig.getMethodName() + "()' is not defined in action '" + getAction().getClass() + "'");
} catch (InvocationTargetException e) {
// We try to return the source exception.
Throwable t = e.getTargetException();
if (t instanceof Exception) {
throw (Exception) t;
} else {
throw e;
}
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/keepeye/archive/2005/06/16/390257.aspx
这个类是静态工具类,其内的方法均依赖com.opensymphony.xwork.ActionContext类,而这个类提供了Action类的执行上下文.我们跟踪这个上下文的生命周期:
客户请求发送到Webserver,它将请求转发到Servlet容器,容器匹配一个Sertlet,然后调用其sevice()方法.在WebWork中这个servlet是ServletDispatcher,其中的serviceAction方法通过代理模式从WebWork进入到XWork对象世界,在那里对客户请求数据对象执行处理,通过执行根据配置上下文和执行上下文设置的Action和result把响应数据发回客户端,发回的动作可能发生在Result中,也可能发生在Interceptor中.开始代码之旅.
下面是serviceAction代码:
public void serviceAction(HttpServletRequest request, HttpServletResponse response, String namespace, String actionName, Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap) {
HashMap extraContext = createContextMap(requestMap, parameterMap, sessionMap, applicationMap, request, response, getServletConfig());
extraContext.put(SERVLET_DISPATCHER, this);
// If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
OgnlValueStack stack = (OgnlValueStack) request.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY);
if (stack != null) {
extraContext.put(ActionContext.VALUE_STACK,new OgnlValueStack(stack));
}
try {
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
proxy.execute();
// If there was a previous value stack then set it back onto the request
if (stack != null){
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY,stack);
}
} catch (ConfigurationException e) {
log.error("Could not find action", e);
sendError(request, response, HttpServletResponse.SC_NOT_FOUND, e);
} catch (Exception e) {
log.error("Could not execute action", e);
sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
方法createContextMap执行数据的包装:
public static HashMap createContextMap(Map requestMap, Map parameterMap, Map sessionMap, Map applicationMap, HttpServletRequest request, HttpServletResponse response, ServletConfig servletConfig) {
HashMap extraContext = new HashMap();
extraContext.put(ActionContext.PARAMETERS, parameterMap);
extraContext.put(ActionContext.SESSION, sessionMap);
extraContext.put(ActionContext.APPLICATION, applicationMap);
extraContext.put(ActionContext.LOCALE, (locale == null) ? request.getLocale() : locale);
extraContext.put(HTTP_REQUEST, request);
extraContext.put(HTTP_RESPONSE, response);
extraContext.put(SERVLET_CONFIG, servletConfig);
extraContext.put(ComponentInterceptor.COMPONENT_MANAGER, request.getAttribute(ComponentManager.COMPONENT_MANAGER_KEY));
// helpers to get access to request/session/application scope
extraContext.put("request", requestMap);
extraContext.put("session", sessionMap);
extraContext.put("application", applicationMap);
extraContext.put("parameters", parameterMap);
AttributeMap attrMap = new AttributeMap(extraContext);
extraContext.put("attr", attrMap);
return extraContext;
}
众所周知,不仅WebWork能使用XWork,而且还可以有类似的FtpWork,MailWork,JMSWork能够替代WebWork来使用Xwork,为什么能够这样,因为Xwork的使用方式.在上面的serviceAction方法中:
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext);
request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());
proxy.execute();
这些代码就是这种方式的体现:动作代理-动作调用-具体的动作.为使客户代码不绑定到特定代理,XWork使用了一个工厂模式,提供工厂类 ActionProxyFactory.
方法createActionProxy实际调用导致一个ActionProxy接口的缺省实现DefaultActionProxy被实例化:
它的构造器是:
protected ActionInvocation invocation;
protected DefaultActionProxy(String namespace, String actionName, Map extraContext, boolean executeResult) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating an DefaultActionProxy for namespace " + namespace + " and action name " + actionName);
}
this.actionName = actionName;
this.namespace = namespace;
this.executeResult = executeResult;
this.extraContext = extraContext;
config = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName);
if (config == null) {
String message;
throw new ConfigurationException(message);
}
prepare();
}
protected void prepare() throws Exception {
//创建ActionInvocation 实例化的仍然是由代理工厂类的工厂方法进行,实例化该接口的缺省 实现DefaultActionInvocation.
invocation = ActionProxyFactory.getFactory().createActionInvocation(this, extraContext);
}
下面是proxy.execute()的细节:
public String execute() throws Exception {
ActionContext nestedContext = ActionContext.getContext();
ActionContext.setContext(invocation.getInvocationContext());
String retCode = null;
try {
retCode = invocation.invoke();
} finally {
ActionContext.setContext(nestedContext);
}
return retCode;
}
最后,看看这个类: DefaultActionInvocation类的invoke方法是如何处理extraContext,先看初始化过程,从构造器开始:
protected DefaultActionInvocation(ActionProxy proxy, Map extraContext, boolean pushAction) throws Exception {
this.proxy = proxy;
this.extraContext = extraContext;
this.pushAction = pushAction;
init();
}
方法init定义,把extraContext转换到invocationContext中,并获得拦截器清单.
private void init() throws Exception {
Map contextMap = createContextMap();
createAction();
if (pushAction) {
stack.push(action);
}
invocationContext = new ActionContext(contextMap);
invocationContext.setName(proxy.getActionName());
List interceptorList = new ArrayList(proxy.getConfig().getInterceptors());
interceptors = interceptorList.iterator();
}
在下面这个方法中获得动作上下文contextMap,并把extraContext包含其中.
protected Map createContextMap() {
Map contextMap;
if ((extraContext!=null)&& (extraContext.containsKey(ActionContext.VALUE_STACK))) {
// In case the ValueStack was passed in
stack = (OgnlValueStack) extraContext.get(ActionContext.VALUE_STACK);
if (stack == null) {
throw new IllegalStateException("There was a null Stack set into the extra params.");
}
contextMap = stack.getContext();
} else {
// create the value stack
// this also adds the ValueStack to its context
stack = new OgnlValueStack();
// create the action context
contextMap = stack.getContext();
}
// put extraContext in
if (extraContext != null) {
contextMap.putAll(extraContext);
}
//put this DefaultActionInvocation into the context map
contextMap.put(ActionContext.ACTION_INVOCATION, this);
return contextMap;
}
protected void createAction() {
// load action
try {
action = ObjectFactory.getObjectFactory().buildAction(proxy.getConfig());
} catch (InstantiationException e) {
throw new XworkException("Unable to intantiate Action!", e);
} catch (IllegalAccessException e) {
throw new XworkException("Illegal access to constructor, is it public?", e);
} catch (ClassCastException e) {
throw new XworkException("Action class " + proxy.getConfig().getClassName() + " does not implement " + Action.class.getName(), e);
} catch (Exception e) {
String gripe = "";
if (proxy == null) {
gripe = "Whoa! No ActionProxy instance found in current ActionInvocation. This is bad ... very bad";
} else if (proxy.getConfig() == null) {
gripe = "Sheesh. Where'd that ActionProxy get to? I can't find it in the current ActionInvocation!?";
} else if (proxy.getConfig().getClassName() == null) {
gripe = "No Action defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'";
} else {
gripe = "Unable to instantiate Action, " + proxy.getConfig().getClassName() + ", defined for '" + proxy.getActionName() + "' in namespace '" + proxy.getNamespace() + "'";
}
gripe += (((" -- " + e.getMessage()) != null) ? e.getMessage() : " [no message in exception]");
throw new XworkException(gripe, e);
}
}
初始化结束了, 接下来看看invocation.invoke()到底做了什么:
public String invoke() throws Exception {
if (executed) {
throw new IllegalStateException("Action has already executed");
}
if (interceptors.hasNext()) {
Interceptor interceptor = (Interceptor) interceptors.next();
在这个类中,并没有调用getResult(),因为这个方法是由某些拦截器调用的,例如: ExecuteAndWaitInterceptor, TokenSessionStoreInterceptor,如果自己需要,也可以创建自己的拦截器,并在其中访问它.
通过Interceptor接口中的String intercept(ActionInvocation invocation) throws Exception可以看到, 参数invocation已经携带了所有能处理的数据了.
resultCode = interceptor.intercept(this);
} else {
resultCode = invokeAction(getAction(), proxy.getConfig());
}
if (!executed) {
if (preResultListeners != null) {
for (Iterator iterator = preResultListeners.iterator();
iterator.hasNext();) {
PreResultListener listener = (PreResultListener) iterator.next();
listener.beforeResult(this, resultCode);
}
}
now execute the result, if we're supposed to,如果不期望执行Result,那么在代理中设置proxy.getExecuteResult(false)即可,有时候是需要这样的,如TokenSessionStoreInterceptor;
if (proxy.getExecuteResult()) {
executeResult();
}
executed = true;
}
return resultCode;
}
在这个方法中,调用了Result接口的方法execute(ActionInvocation),当该方法返回时一个请求响应回合就完成了.
private void executeResult() throws Exception {
result = createResult();
if (result != null) {
result.execute(this);
} else if (!Action.NONE.equals(resultCode)) {
LOG.warn("No result defined for action " + getAction().getClass().getName() + " and result " + getResultCode());
}
}
public Result createResult() throws Exception {
Map results = proxy.getConfig().getResults();
ResultConfig resultConfig = (ResultConfig) results.get(resultCode);
Result newResult = null;
if (resultConfig != null) {
try {
newResult = ObjectFactory.getObjectFactory().buildResult(resultConfig);
} catch (Exception e) {
LOG.error("There was an exception while instantiating the result of type " + resultConfig.getClassName(), e);
throw e;
}
}
return newResult;
}
public Result getResult() throws Exception {
Result returnResult = result;
// If we've chained to other Actions, we need to find the last result
while (returnResult instanceof ActionChainResult) {
ActionProxy aProxy = ((ActionChainResult) returnResult).getProxy();
if (aProxy != null) {
Result proxyResult = aProxy.getInvocation().getResult();
if ((proxyResult != null) && (aProxy.getExecuteResult())) {
returnResult = proxyResult;
} else {
break;
}
} else {
break;
}
}
return returnResult;
}
protected String invokeAction(Action action, ActionConfig actionConfig) throws Exception {
if (proxy.getConfig().getMethodName() == null) {
return getAction().execute();
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing action method = " + actionConfig.getMethodName());
}
try {
Method method = actionConfig.getMethod(action.getClass());
if (action instanceof Proxy) {
try {
return (String) Proxy.getInvocationHandler(action).invoke(action, method, new Object[0]);
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new Exception("Error invoking on proxy: " + throwable.getMessage());
}
} else {
return (String) method.invoke(action, new Object[0]);
}
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Method '" + actionConfig.getMethodName() + "()' is not defined in action '" + getAction().getClass() + "'");
} catch (InvocationTargetException e) {
// We try to return the source exception.
Throwable t = e.getTargetException();
if (t instanceof Exception) {
throw (Exception) t;
} else {
throw e;
}
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/keepeye/archive/2005/06/16/390257.aspx
发表评论
-
实现xwork配置文件的自动加载-摘自http://blog.csdn.net/snow_fox_yaya/article/details/2218141
2012-07-09 15:54 1935一、 如果配置文件struts ... -
Struts2 s:if 界面判断集合or对象
2011-10-28 17:10 2766判断 ArrayList size 是否为0 <s:if ... -
struts2日期标签datetimepicker
2011-10-27 15:30 1326http://blog.csdn.net/wuxinfengj ... -
struts2的checkbox标签--value和fieldValue
2011-10-19 15:21 2339struts2的checkbox标签在使用的时候需要注意它的两 ... -
struts iterator
2011-03-24 20:19 766<s:iterator value="dept ... -
struts2+jsonplugin
2011-03-02 12:00 10821、引入包(本文中的包全部引自struts-2.1.8.1\l ... -
Struts2返回JSON
2011-03-02 11:53 42231.导入jsonplugin包 Struts2.16:导入j ... -
JSP页面获取ValueStack中的值
2011-02-22 09:48 1743我们知道Struts2会将Action中的属性存放到Value ... -
webwork.properties 详解
2010-12-23 18:19 985WebWork有很多属性可以根据需要改变.要改变它们,请指定c ... -
webwork中关于ValueStack的描述
2010-12-08 11:05 1146关于ValueStack的描述: 1、 ValueStac ... -
struts2 标签
2010-11-28 08:51 998struts2的select标签中,常用的有以下几个属性: ... -
struts与webwork
2010-11-08 19:55 874不想过多的争论struts与webwork的优越性,只是自己做 ... -
Struts2支持动态方法调用
2010-05-15 23:50 2301在 WebWork2 中,可以使用感叹号(!)来指定要执行(或 ... -
struts2中减少action数量(通配符使用)
2009-12-01 20:40 1194struts2中减少action数量(通配符使用) 如str ...
相关推荐
WebWork 的工作流程主要涉及以下几个关键组件: 1. **Action**: - Action 类是业务逻辑的载体,负责处理用户请求并返回结果。Action 类通常会实现一个特定的接口,如`com.opensymphony.xwork2.ActionSupport`,并...
WebWork2.0是一款基于Java的企业级Web应用框架,它为开发者提供了强大的MVC(Model-View-Controller)架构支持,旨在简化Web应用程序的开发流程,提高代码的可维护性和可扩展性。本讲解将围绕WebWork2.0的核心概念、...
在深入研究WebWork源码时,开发者可以了解其内部的工作原理,包括请求处理流程、模型绑定、拦截器链的执行、异常处理机制等,这对于提高编程技能和理解MVC框架的设计模式非常有帮助。此外,查看`displaytag-1.0`源码...
WebWork的执行流程涉及到ActionProxy和ActionInvocation两个概念。ActionProxy负责管理Action的生命周期,包括创建和执行Action。而ActionInvocation则代表了Action执行的状态,它持有Action实例和一系列Interceptor...
4. **Interceptors(拦截器)**:WebWork引入了拦截器的概念,它们在Action执行前后执行,可以实现通用的功能,如权限检查、日志记录等。在源码中,你会看到这些拦截器的实现。 5. **Value Stack(值栈)**:...
1. 动作拦截器(Interceptors):拦截器可以对动作执行前后的流程进行增强,如权限检查、日志记录等。通过配置,可以灵活地组合和应用拦截器。 2. 数据验证(Validation):WebWork2提供了强大的数据验证机制,可以...
WebWork的工作流程主要包含以下几个步骤: 1. **接收HTTP请求**:当用户通过浏览器发送HTTP请求时,请求首先被服务器接收。 2. **请求解析**:服务器将请求传递给WebWork的`ServletDispatcher`,`ServletDispatcher...
通过构建这个简单的示例,开发者不仅能够理解WebWork的基本工作流程,还能接触到Action、ActionContext、ResultType等关键概念。Action是业务逻辑的主要承载者,ActionContext则负责管理Action的执行上下文,...
WebWork 2.0引入了Action驱动模式,这一模式允许开发者定义不同的Action来处理不同的用户请求,每个Action可以执行特定的业务逻辑并返回相应的结果。与传统的Servlet模型相比,Action驱动模式提供了更清晰的代码结构...
3. **拦截器(Interceptor)**:类似于AOP(面向切面编程),WebWork允许开发者定义拦截器来处理共性任务,如日志记录、事务管理、权限检查等,这些任务可以在动作执行前后自动进行。 4. **强大的表单处理**:...
2. Action与ActionForm:Action是WebWork中的控制器组件,处理用户的请求,执行相应的业务逻辑,并将结果传递给视图。ActionForm则用于封装请求参数,作为模型与控制器之间的数据载体。 二、WebWork架构 1. 请求...
3. **拦截器(Interceptors)**:WebWork引入了拦截器的概念,允许在Action执行前后插入自定义逻辑,如日志、事务管理等,增强了可扩展性。 4. **OGNL(Object-Graph Navigation Language)**:WebWork使用OGNL作为...
这些配置可以控制Action的执行流程,如错误处理、国际化等。 7. **ActionForm**:虽然在WebWork 2.x版本中,ActionForm的概念已经被弱化,但在早期版本中,ActionForm用于封装表单数据并传递到Action中。现在,可以...
让我们深入探讨WebWork的核心概念、Action的创建以及如何实现基本的流程控制。 **WebWork核心概念** 1. **Action**: 在WebWork中,Action是业务逻辑的主要载体。它负责接收来自视图层(如JSP)的请求,处理业务...
1. **动作映射(Action Mapping)**:WebWork2通过配置文件定义动作映射,将URL请求映射到特定的Java类方法,简化了请求处理流程。 2. **强大的拦截器(Interceptor)机制**:拦截器可以在动作执行前后执行预处理和...
**结果类型**:WebWork支持多种结果类型,如dispatcher、redirect、stream等,用于控制请求的处理流程和响应的方式。 ### WebWork框架的特点 - **灵活性**:WebWork提供了丰富的配置选项和插件系统,使得开发者...
4. **Interceptor(拦截器)**:拦截器是WebWork2的一个重要特性,它们是可复用的代码片段,可以插入到Action执行流程中,实现如日志记录、权限检查、事务管理等功能。通过配置,可以灵活地调整拦截器链。 5. **...
WebWork是一个基于Java的MVC(Model-View-Controller)框架,它在早期的Web开发中扮演了...通过研究这个MyEclipse项目,你可以深入理解WebWork的生命周期、数据绑定和控制流程,为后续的Java EE开发打下坚实的基础。