本文主要通过三个方面给大家介绍webwork action调用相关知识,三个方面分别是:
1.这部分框架类关系
2.Webwork 获取和包装 web 参数
3.DefaultActionProxyFactory、DefaultActionProxy、DefaultActionInvocation
一路走来,终于要开始 webwork 核心业务类的总结,webwork 通过对客户端传递的 web 参数重新包装,进行执行业务 Action 类,并反馈执行结果,本篇源码分析对应下图 WebWork 框架流转图中红色框的地方。
1.这部分框架类关系
2.Webwork 获取和包装 web 参数
"htmlcode">
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { try { if (encoding != null) { try { request.setCharacterEncoding(encoding); } catch (Exception localException) { } } if (locale != null) { response.setLocale(locale); } if (this.paramsWorkaroundEnabled) { request.getParameter("foo"); } request = wrapRequest(request); //封装 request请求 serviceAction(request, response, getNameSpace(request), getActionName(request), getRequestMap(request), getParameterMap(request), getSessionMap(request), getApplicationMap()); } catch (IOException e) { String message = "Could not wrap servlet request with MultipartRequestWrapper!"; log.error(message, e); sendError(request, response, , new ServletException(message, e)); } }
"/my/MyAction.action"则返回"/my",具体实现如下:
protected String getNameSpace(HttpServletRequest request){ String servletPath = request.getServletPath(); return getNamespaceFromServletPath(servletPath); } public static String getNamespaceFromServletPath(String servletPath){ servletPath = servletPath.substring(, servletPath.lastIndexOf("/")); return servletPath; }
"MyAction.action"则返回"MyAction",具体实现如下:
protected String getActionName(HttpServletRequest request){ String servletPath = (String)request.getAttribute("javax.servlet.include.servlet_path"); if (servletPath == null) { servletPath = request.getServletPath(); } return getActionName(servletPath); } protected String getActionName(String name){ int beginIdx = name.lastIndexOf("/"); int endIdx = name.lastIndexOf("."); return name.substring(beginIdx == - "htmlcode">protected Map getRequestMap(HttpServletRequest request){ return new RequestMap(request); }
"htmlcode">
protected Map getParameterMap(HttpServletRequest request) throws IOException{ return request.getParameterMap(); }"htmlcode">
protected Map getSessionMap(HttpServletRequest request){ return new SessionMap(request); }"htmlcode">
protected Map getApplicationMap(){ return new ApplicationMap(getServletContext()); }"htmlcode">
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("com.opensymphony.xwork.dispatcher.ServletDispatcher", this); OgnlValueStack stack = (OgnlValueStack) request.getAttribute("webwork.valueStack"); if (stack != null) { extraContext.put("com.opensymphony.xwork.util.OgnlValueStack.ValueStack", new OgnlValueStack(stack)); } try { ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext); request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack()); proxy.execute(); if (stack != null) { request.setAttribute("webwork.valueStack", stack); } } catch (ConfigurationException e) { log.error("Could not find action", e); sendError(request, response, 404, e); } catch (Exception e) { log.error("Could not execute action", e); sendError(request, response, 500, e); } }"color: #0000ff">3.DefaultActionProxyFactory、DefaultActionProxy、DefaultActionInvocation
前戏终于做完了,Action 调用的三兄弟要登场进行最重要的操作了,就是下面这三句代码,与Webwork 学习之路(五)请求跳转前 xwork.xml 的读取代码有非常相似的写法和设计:
ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraContext); request.setAttribute("webwork.valueStack", proxy.getInvocation().getStack());
proxy.execute(); "htmlcode">
static ActionProxyFactory factory = new DefaultActionProxyFactory(); public static void setFactory(ActionProxyFactory factory){ factory = factory; } public static ActionProxyFactory getFactory(){ return factory; }"htmlcode">
public ActionProxy createActionProxy(String namespace, String actionName, Map extraContext)throws Exception { setupConfigIfActionIsCommand(namespace, actionName); return new DefaultActionProxy(namespace, actionName, extraContext, true); } "Creating an DefaultActionProxy for namespace " + namespace + " and action name " + actionName); } this.actionName = actionName; this.namespace = namespace; this.executeResult = executeResult; this.extraContext = extraContext; this.config = ConfigurationManager.getConfiguration().getRuntimeConfiguration().getActionConfig(namespace, actionName); if (this.config == null) { String message; String message; if ((namespace != null) && (namespace.trim().length() > 0)) { message = LocalizedTextUtil.findDefaultText("xwork.exception.missing-package-action", Locale.getDefault(), new String[] { namespace, actionName }); } else { message = LocalizedTextUtil.findDefaultText("xwork.exception.missing-action", Locale.getDefault(), new String[] { actionName }); } throw new ConfigurationException(message); } prepare(); }"htmlcode">
protected void prepare() throws Exception { this.invocation = ActionProxyFactory.getFactory().createActionInvocation(this, this.extraContext); }以上所示是针对Webwork中Action 调用 的相关知识,希望对大家有所帮助。
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。