锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
聽聽聽聽聽
鍦ㄦ柊鐨勬灦鏋勪腑WebWork2.x鐨勪綔鐢ㄦ槸璐熻矗灝嗙敤鎴風殑HTTP璇鋒眰鍒嗙鍑烘潵,浣跨殑璇鋒眰瀹屽叏鐨勮劚紱籗ervlet API,鐒跺悗灝嗚繖浜涜姹傜敤Map鐨勬柟寮忎紶鍏Work1.x,涓擷Work1.x閫氳繃Interceptor 灝哅ap涓殑鏁版嵁浼犲埌鎴戜滑鐨刅O涓?鐒跺悗鐢卞搴旂殑鑷畾涔堿ction鏉ヨ皟鐢?
聽聽聽聽聽聽 棣栧厛鎵撳紑DispatcherUtils.java,瀹冨湪com.opensymphony.webwork.dispatcher鍖呬笅闈€?/p>
聽聽聽聽聽聽 鎵懼埌serviceAction榪欎釜鏂規硶錛屽畠瀹炰緥鍖栦簡Map璇鋒眰錛屼粠璇鋒眰鐨勬湇鍔′腑瑙f瀽鍑哄搴旂殑Action鍚嶇О銆?br />聽聽聽聽聽聽 HashMap extraContext = createContextMap(requestMap, params, session, application, request, response, context);
聽聽聽聽聽聽 OgnlValueStack stack = (OgnlValueStack) request.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY);
聽聽聽聽聽聽聽 if (stack != null) {
聽聽聽聽聽聽聽聽聽聽聽 extraContext.put(ActionContext.VALUE_STACK, new OgnlValueStack(stack));
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽 try {
聽聽聽聽聽聽聽聽聽聽聽 String namespace = mapping.getNamespace();
聽聽聽聽聽聽聽聽聽聽聽 String name = mapping.getName();
聽聽聽聽聽聽聽聽聽聽聽 String method = mapping.getMethod();
聽聽聽聽聽聽聽聽聽聽聽 String id = request.getParameter("continue");
聽聽聽聽聽聽聽聽聽聽聽 if (id != null) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 extraContext.put("__continue", id);
聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽 // if the ActionMapping says to go straight to a result, do it!
聽聽聽聽聽聽聽聽聽聽聽 if (mapping.getResult() != null) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Result result = mapping.getResult();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 result.execute(proxy.getInvocation());
聽聽聽聽聽聽聽聽聽聽聽 } else {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 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 銆傘傘傘傘傘傘?br />聽聽聽聽聽聽 鎵懼埌createContextMap榪欎釜鏂規硶錛屽畠閬嶅巻浜咹ttpServletRequest,HttpSession,ServletContext涓殑鏁版嵁錛屽皢浠栦滑澶嶅埗鍒癕ap涓粠鑰屽唴閮ㄧ粨鏋勪笌Servlet API鐩稿垎紱匯?br />聽聽聽聽聽聽聽聽 public HashMap createContextMap(Map requestMap,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Map parameterMap,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Map sessionMap,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Map applicationMap,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletRequest request,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 HttpServletResponse response,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ServletContext servletContext) {
聽聽聽聽聽聽聽 HashMap extraContext = new HashMap();
//瀛樻斁HTTP涓笂浼犳枃浠剁殑request聽 session璇鋒眰
聽聽聽聽聽聽聽 extraContext.put(ActionContext.PARAMETERS, new HashMap(parameterMap));
聽聽聽聽聽聽聽 extraContext.put(ActionContext.SESSION, sessionMap);
聽聽聽聽聽聽聽 extraContext.put(ActionContext.APPLICATION, applicationMap);
聽聽聽聽聽聽聽 extraContext.put(ActionContext.LOCALE, (locale == null) ? request.getLocale() : locale);
聽聽聽聽聽聽聽 extraContext.put(ActionContext.DEV_MODE, Boolean.valueOf(devMode));
聽聽聽聽聽聽聽 extraContext.put(WebWorkStatics.HTTP_REQUEST, request);
聽聽聽聽聽聽聽 extraContext.put(WebWorkStatics.HTTP_RESPONSE, response);
聽聽聽聽聽聽聽 extraContext.put(WebWorkStatics.SERVLET_CONTEXT, servletContext);
聽聽聽聽聽聽聽 extraContext.put(ComponentInterceptor.COMPONENT_MANAGER, request.getAttribute(ComponentManager.COMPONENT_MANAGER_KEY));
聽聽聽聽聽聽聽 // 榪欓噷鐢ㄤ簬瀛樻斁HTTP涓殑request聽 session璇鋒眰
聽聽聽聽聽聽聽 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;
聽聽聽 }
聽聽聽聽聽聽 鍒涘緩Action錛岀敱ActionProxy鏉ュ畬鎴愩?br />聽聽聽聽聽聽聽聽聽聽聽 ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, name, extraContext);
聽聽聽聽聽聽聽聽聽聽聽 proxy.setMethod(method);
聽聽聽聽聽聽聽聽聽聽聽 request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack());