struts2 架构图如下图所示:

依照上图,我们可以看出一个请求在struts的处理大概有如下步骤:

  1、客户端初始化一个指向Servlet容器(例如Tomcat)的请求;

  2、这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过滤器对于Struts2和其他框架的集成很有帮助,例如:SiteMesh Plugin);

  3、接着StrutsPrepareAndExecuteFilter被调用,StrutsPrepareAndExecuteFilter询问ActionMapper来决定这个请求是否需要调用某个Action;

  4、如果ActionMapper决定需要调用某个Action,FilterDispatcher把请求的处理交给ActionProxy;

  5、ActionProxy通过Configuration Manager询问框架的配置文件,找到需要调用的Action类;

  6、ActionProxy创建一个ActionInvocation的实例。

  7、ActionInvocation实例使用命名模式来调用,在调用Action的过程前后,涉及到相关拦截器(Intercepter)的调用。

  8、一旦Action执行完毕,ActionInvocation负责根据struts.xml中的配置找到对应的返回结果。返回结果通常是(但不总是,也可能是另外的一个Action链)一个需要被表示的JSP或者FreeMarker的模版。在表示的过程中可以使用Struts2 框架中继承的标签。在这个过程中需要涉及到ActionMapper。

Struts启动流程:

1、Tomcat启动,首先执行org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter中的init()方法,init()方法加载了default.properties,struts-default.xml,struts-plugin.xml,struts.xml配置文件,如果这三个文件有相同的项,后面覆盖前面的,其中struts.xml文件必须放在src目录下

 public void init(FilterConfig filterConfig) throws ServletException {
InitOperations init = new InitOperations();
Dispatcher dispatcher = null;
try {
//封装filterConfig,其中有个主要方getInitParameterNames将参数名字以String格式存储在List中
FilterHostConfig config = new FilterHostConfig(filterConfig);
init.initLogging(config);
//创建dispatcher ,并初始化
dispatcher = init.initDispatcher(config);
init.initStaticContentLoader(config, dispatcher);
prepare = new PrepareOperations(dispatcher);
execute = new ExecuteOperations(dispatcher);
this.excludedPatterns = init.buildExcludedPatternsList(dispatcher); postInit(dispatcher, filterConfig);
} finally {
if (dispatcher != null) {
dispatcher.cleanUpAfterInit();
}
init.cleanup();
}
}

只有短短的几行代码,getInitParameterNames是这个类的核心,将Filter初始化参数名称有枚举类型转为Iterator。此类的主要作为是对filterConfig 封装。

  接下来,看下StrutsPrepareAndExecuteFilter中init方法中dispatcher = init.initDispatcher(config);这是初始化dispatcher的,是通过init对象的initDispatcher方法来初始化的,init是InitOperations类的对象,我们看看InitOperations中initDispatcher方法:

1  public Dispatcher initDispatcher( HostConfig filterConfig ) {
2 Dispatcher dispatcher = createDispatcher(filterConfig);
3 dispatcher.init();
4 return dispatcher;
5 }

创建Dispatcher,会读取 filterConfig 中的配置信息,将配置信息解析出来,封装成为一个Map,然后根据servlet上下文和参数Map构造Dispatcher :

 private Dispatcher createDispatcher( HostConfig filterConfig ) {
//存放参数的Map
Map<String, String> params = new HashMap<String, String>();
//将参数存放到Map
for ( Iterator e = filterConfig.getInitParameterNames(); e.hasNext(); ) {
String name = (String) e.next();
String value = filterConfig.getInitParameter(name);
params.put(name, value);
}
//根据servlet上下文和参数Map构造Dispatcher
return new Dispatcher(filterConfig.getServletContext(), params);
}

这样dispatcher对象创建完成,接着就是dispatcher对象的初始化,打开Dispatcher类,看到它的init方法如下:

 public void init() {

         if (configurationManager == null) {
configurationManager = createConfigurationManager(DefaultBeanSelectionProvider.DEFAULT_BEAN_NAME);
} try {
init_FileManager();
         //加载default.properties文件
init_DefaultProperties(); // [1]
         //加载struts-default.xml,struts-plugin.xml文件
init_TraditionalXmlConfigurations(); // [2]
init_LegacyStrutsProperties(); // [3]
init_CustomConfigurationProviders(); // [5]
init_FilterInitParameters() ; // [6]
init_AliasStandardObjects() ; // [7] Container container = init_PreloadConfiguration();
container.inject(this);
init_CheckWebLogicWorkaround(container); if (!dispatcherListeners.isEmpty()) {
for (DispatcherListener l : dispatcherListeners) {
l.dispatcherInitialized(this);
}
}
errorHandler.init(servletContext); } catch (Exception ex) {
if (LOG.isErrorEnabled())
LOG.error("Dispatcher initialization failed", ex);
throw new StrutsException(ex);
}
}

这里主要是加载一些配置文件的,将按照顺序逐一加载:default.properties,struts-default.xml,struts-plugin.xml,struts.xml,主要是由xwork核心类加载的,代码在xwork-core\src\main\java\com\opensymphony\xwork2\config\providers包里面。

  现在,我们回到StrutsPrepareAndExecuteFilter类中,刚才我们分析了StrutsPrepareAndExecuteFilter类的init方法,该方法在web容器一启动就会调用的,当用户访问某个action的时候,首先调用核心过滤器StrutsPrepareAndExecuteFilter的doFilter方法,该方法内容如下:

 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

         HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res; try {
if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
chain.doFilter(request, response);
} else {
prepare.setEncodingAndLocale(request, response);
prepare.createActionContext(request, response);
prepare.assignDispatcherToThread();
request = prepare.wrapRequest(request);
ActionMapping mapping = prepare.findActionMapping(request, response, true);
if (mapping == null) {
boolean handled = execute.executeStaticResourceRequest(request, response);
if (!handled) {
chain.doFilter(request, response);
}
} else {
execute.executeAction(request, response, mapping);
}
}
} finally {
prepare.cleanupRequest(request);
}
}

下面对doFilter方法中的重点部分一一讲解:

(1)prepare.setEncodingAndLocale(request, response);

  第8行是调用prepare对象的setEncodingAndLocale方法,prepare是PrepareOperations类的对象,PrepareOperations类是用来做请求准备工作的。我们看下PrepareOperations类中的setEncodingAndLocale方法:

  public void prepare(HttpServletRequest request, HttpServletResponse response) {
String encoding = null;
if (defaultEncoding != null) {
encoding = defaultEncoding;
}
// check for Ajax request to use UTF-8 encoding strictly http://www.w3.org/TR/XMLHttpRequest/#the-send-method
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
encoding = "UTF-8";
} Locale locale = null;
if (defaultLocale != null) {
locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
} if (encoding != null) {
applyEncoding(request, encoding);
} if (locale != null) {
response.setLocale(locale);
} if (paramsWorkaroundEnabled) {
request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request
}
}

我们可以看到该方法只是简单的设置了encoding 和locale ,做的只是一些辅助的工作。

(2)prepare.createActionContext(request, response)

  我们回到StrutsPrepareAndExecuteFilter的doFilter方法,看到第10行代码:prepare.createActionContext(request, response);这是action上下文的创建,ActionContext是一个容器,这个容器主要存储request、session、application、parameters等相关信息.ActionContext是一个线程的本地变量,这意味着不同的action之间不会共享ActionContext,所以也不用考虑线程安全问题,其实质是一个Map,key是标示request、session、……的字符串,值是其对应的对象,我们可以看到com.opensymphony.xwork2.ActionContext类中时如下定义的:

 public ActionContext createActionContext(HttpServletRequest request, HttpServletResponse response) {
ActionContext ctx;
Integer counter = 1;
Integer oldCounter = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
if (oldCounter != null) {
counter = oldCounter + 1;
} ActionContext oldContext = ActionContext.getContext();
if (oldContext != null) {
// detected existing context, so we are probably in a forward
ctx = new ActionContext(new HashMap<String, Object>(oldContext.getContextMap()));
} else {
ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack();
stack.getContext().putAll(dispatcher.createContextMap(request, response, null));
ctx = new ActionContext(stack.getContext());
}
request.setAttribute(CLEANUP_RECURSION_COUNTER, counter);
ActionContext.setContext(ctx);
return ctx;
}

(3)request = prepare.wrapRequest(request)

  我们再次回到StrutsPrepareAndExecuteFilter的doFilter方法中,看到第15行:request = prepare.wrapRequest(request);这一句是对request进行包装的,我们看下prepare的wrapRequest方法:

  public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException {
// don't wrap more than once
if (request instanceof StrutsRequestWrapper) {
return request;
} String content_type = request.getContentType();
if (content_type != null && content_type.contains("multipart/form-data")) {
MultiPartRequest mpr = getMultiPartRequest();
LocaleProvider provider = getContainer().getInstance(LocaleProvider.class);
request = new MultiPartRequestWrapper(mpr, request, getSaveDir(), provider, disableRequestAttributeValueStackLookup);
} else {
request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup);
} return request;
}

此次包装根据请求内容的类型不同,返回不同的对象,如果为multipart/form-data类型,则返回MultiPartRequestWrapper类型的对象,该对象服务于文件上传,否则返回StrutsRequestWrapper类型的对象,MultiPartRequestWrapper是StrutsRequestWrapper的子类,而这两个类都是HttpServletRequest接口的实现。

(4)ActionMapping mapping = prepare.findActionMapping(request, response, true)

  包装request后,通过ActionMapper的getMapping()方法得到请求的Action,Action的配置信息存储在ActionMapping对象中,如StrutsPrepareAndExecuteFilter的doFilter方法中第16行:ActionMapping mapping = prepare.findActionMapping(request, response, true);我们找到prepare对象的findActionMapping方法:

 public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response, boolean forceLookup) {
ActionMapping mapping = (ActionMapping) request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
if (mapping == null || forceLookup) {
try {
mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
if (mapping != null) {
request.setAttribute(STRUTS_ACTION_MAPPING_KEY, mapping);
}
} catch (Exception ex) {
dispatcher.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
}
} return mapping;
}

下面是ActionMapper接口的实现类DefaultActionMapper的getMapping()方法的源代码:

 public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) {
ActionMapping mapping = new ActionMapping();
//获得请求的uri,即请求路径URL中工程名以后的部分,如/userAction.action
String uri = RequestUtils.getUri(request);
//修正url的带;jsessionid 时找不到的bug
int indexOfSemicolon = uri.indexOf(";");
uri = (indexOfSemicolon > -1) ? uri.substring(0, indexOfSemicolon) : uri;
//删除扩展名,如.action或者.do
uri = dropExtension(uri, mapping);
if (uri == null) {
return null;
}
//从uri中分离得到请求的action名、命名空间。
parseNameAndNamespace(uri, mapping, configManager);
//处理特殊的请求参数
handleSpecialParameters(request, mapping);
//如果允许动态方法调用,即形如/userAction!getAll.action的请求,分离action名和方法名
return parseActionName(mapping);
}

下面对getMapping方法中的重要部分一一讲解:

  ①:parseNameAndNamespace(uri, mapping, configManager)

  我们主要看下第14行的parseNameAndNamespace(uri, mapping, configManager);这个方法的主要作用是分离出action名和命名空间:

 protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) {
String namespace, name;
int lastSlash = uri.lastIndexOf("/");
if (lastSlash == -1) {
namespace = "";
name = uri;
} else if (lastSlash == 0) {
// ww-1046, assume it is the root namespace, it will fallback to
// default
// namespace anyway if not found in root namespace.
namespace = "/";
name = uri.substring(lastSlash + 1);
} else if (alwaysSelectFullNamespace) {
// Simply select the namespace as everything before the last slash
namespace = uri.substring(0, lastSlash);
name = uri.substring(lastSlash + 1);
} else {
// Try to find the namespace in those defined, defaulting to ""
Configuration config = configManager.getConfiguration();
String prefix = uri.substring(0, lastSlash);
namespace = "";
boolean rootAvailable = false;
// Find the longest matching namespace, defaulting to the default
for (PackageConfig cfg : config.getPackageConfigs().values()) {
String ns = cfg.getNamespace();
if (ns != null && prefix.startsWith(ns) && (prefix.length() == ns.length() || prefix.charAt(ns.length()) == '/')) {
if (ns.length() > namespace.length()) {
namespace = ns;
}
}
if ("/".equals(ns)) {
rootAvailable = true;
}
} name = uri.substring(namespace.length() + 1); // Still none found, use root namespace if found
if (rootAvailable && "".equals(namespace)) {
namespace = "/";
}
} if (!allowSlashesInActionNames) {
int pos = name.lastIndexOf('/');
if (pos > -1 && pos < name.length() - 1) {
name = name.substring(pos + 1);
}
} mapping.setNamespace(namespace);
mapping.setName(cleanupActionName(name));
}

看到上面代码的第14行,参数alwaysSelectFullNamespace我们可以通过名字就能大概猜出来"允许采用完整的命名空间",即设置命名空间是否必须进行精确匹配,true必须,false可以模糊匹配,默认是false。进行精确匹配时要求请求url中的命名空间必须与配置文件中配置的某个命名空间必须相同,如果没有找到相同的则匹配失败。这个参数可通过struts2的"struts.mapper.alwaysSelectFullNamespace"常量配置,如:<constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />。当alwaysSelectFullNamespace为true时,将uri以lastSlash为分割,左边的为namespace,右边的为name。如:http://localhost:8080/myproject/home/actionName!method.action,此时uri为/home/actionName!method.action(不过前面把后缀名去掉了,变成/home/actionName!method),lastSlash的当前值是5,这样namespace为"/home", name为actionName!method。

  我们再看到上面代码第18行到第44行:当上面的所有条件都不满足时,其中包括alwaysSelectFullNamespace 为false(命名空间进行模糊匹配),将由此部分处理,进行模糊匹配。第1句,通过configManager.getConfiguration()从配置管理器中获得配置对象Configuration,Configuration中存放着struts2的所有配置,形式是将xml文档的相应元素封装为java bean,如<package>元素被封装到PackageConfig类中,这个一会儿会用到。第2句按lastSlash将uri截取出prefix,这是一个临时的命名空间,之后将会拿prefix进行模糊匹配。第3句namespace = "",将命名空间暂时设为""。第4句创建并设置rootAvailable,rootAvailable作用是判断配置文件中是否配置了命名空间"/",true为配置了,false未配置,下面for语句将会遍历我们配置的所有包(<package>),同时设置rootAvailable。第5句for,通过config.getPackageConfigs()获得所有已经配置的包,然后遍历。String ns = ((PackageConfig) cfg).getNamespace()获得当前包的命名空间ns,之后的if句是进行模糊匹配的核心,我摘出来单独说,如下:

1 if (ns != null && prefix.startsWith(ns) && (prefix.length() == ns.length() || prefix.charAt(ns.length()) == '/')) {
2 if (ns.length() > namespace.length()) {
3 namespace = ns;
4 }
5 }

ns != null && prefix.startsWith(ns)这部分判断当ns不等于空并且ns是prefix的前缀。prefix.length() == ns.length()当二者长度相等时,结合前面部分就是ns是prefix的前缀并且二者长度相等,最终结论就是ns和prefix相等。如果前面的条件不成立,则说明prefix的长度大于ns。prefix.charAt(ns.length()) == '/')意思是prefix中与ns不相等的字符中的第一个字符必须是"/",也就是说,在命名空间采用斜杠分级的形式中,ns必须是prefix的某一子集,如:/common/home 是用户配置的命名空间,则在http的请求url中,/common/home/index1、/common/home/index2、/common/home/index/aaa 都是正确的,都可以成功的匹配到/common/home,而/common/homeaa、/common/homea/aaa都是错误的。接着if (ns.length() > namespace.length()) 句,目的是找出字符长度最长的。因为命名空间采用的是分级的,则长度越长所表示的越精确,如/common/home/index比/common/home精确。之后将namespace = ns。

  我们接着往下看if ("/".equals(ns)) 当我们配置了"/"这个命名空间时,将rootAvailable = true。name = uri.substring(namespace.length() + 1)句不涉及到命名空间就不说了。if (rootAvailable && "".equals(namespace))如果通过上面的for循环没有找到匹配的命名空间即namespace的值仍然是当初设置的"",但却配置了"/"时,将命名空间设为"/"。

  我们再看到第46到51行那个if语句:

1 if (!allowSlashesInActionNames) {
2 int pos = name.lastIndexOf('/');
3 if (pos > -1 && pos < name.length() - 1) {
4 name = name.substring(pos + 1);
5 }
6 }

allowSlashesInActionNames代表是否允许"/"出现在Action的名称中,默认为false,如果不允许"/"出现在Action名中,并且这时的Action名中有"/",则取"/"后面的部分。

下面是命名空间匹配规则的总结:

(1). 如果请求url中没有命名空间时,将采用"/"作为命名空间。

(2). 当我们将常量 struts.mapper.alwaysSelectFullNamespace设为true时,那么请求url的命名空间必须和配置文件配置的完全相同才能匹配。

当将常量 struts.mapper.alwaysSelectFullNamespace设为false时,那么请求url的命名空间和配置文件配置的可按模糊匹配。规则:

  a.如果配置文件中配置了/common 而url中的命名空间/common、/common/home、/common/home/index等等都是可匹配的,即子命名空间可匹配父命名空间。

  b.如果对于某个url请求中的命名空间同时匹配了俩个或俩个以上的配置文件中配置的命名空间,则选字符最长的,如:当前请求的命名空间为/common/home/index/aaaa,  而我们在配置时同时配置了/common/home、/common/home/index  则将会匹配命名空间最长的,即/common/home/index。

(3).最后,如果请求的命名空间在配置中没有匹配到时,将采用""作为命名空间。如果没有设置为""的命名空间将抛出404错误。

  ②:parseActionName(mapping)

  好了,到这里parseNameAndNamespace方法已经分析完了,我们再次回到getMapping方法中去,看到16行:handleSpecialParameters(request, mapping);好像是处理特殊参数的函数吧,里面有点看不懂,暂时就不管,以后有时间再研究。我们看到18行:return parseActionName(mapping);主要是用来处理形如/userAction!getAll.action的请求,分离action名和方法名:

1 protected ActionMapping parseActionName(ActionMapping mapping) {
2 if (mapping.getName() == null) {
3 return null;
4 }
5 //如果允许动态方法调用
6 if (allowDynamicMethodCalls) {
7 // handle "name!method" convention.
8 String name = mapping.getName();
9 int exclamation = name.lastIndexOf("!");
10 //如果包含"!"就进行分离
11 if (exclamation != -1) {
12 //分离出action名
13 mapping.setName(name.substring(0, exclamation));
14 //分离出方法名
15 mapping.setMethod(name.substring(exclamation + 1));
16 }
17 }
18 return mapping;
19 }

到此为止getMapping方法已经分析结束了!

(5)execute.executeAction(request, response, mapping)

  上面我们分析完了mapping的获取,继续看doFilter方法:

 1 //如果mapping为空,则认为不是调用action,会调用下一个过滤器链,直到获取到mapping才调用action
2 if (mapping == null) {
3 boolean handled = execute.executeStaticResourceRequest(request, response);
4 if (!handled) {
5 chain.doFilter(request, response);
6 }
7 } else {
8 //执行action
9 execute.executeAction(request, response, mapping);
10 }

如果mapping对象不为空,则会执行action,我们看到上面代码第9行:execute是ExecuteOperations类的对象,ExecuteOperations类在包org.apache.struts2.dispatcher.ng下面,我们找到它里面的executeAction方法:

1 public void executeAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
2 dispatcher.serviceAction(request, response, servletContext, mapping);
3 }

我们可以看到它里面只是简单的调用了dispatcher的serviceAction方法:我们找到dispatcher的serviceAction方法:

1 public void serviceAction(HttpServletRequest request, HttpServletResponse response, ServletContext context,
2 ActionMapping mapping) throws ServletException {
3 //封转上下文环境,主要将requestMap、params、session等Map封装成为一个上下文Map
4 Map<String, Object> extraContext = createContextMap(request, response, mapping, context);
5
6 // If there was a previous value stack, then create a new copy and pass it in to be used by the new Action
7 ValueStack stack = (ValueStack) request.getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY);
8 boolean nullStack = stack == null;
9 if (nullStack) {
10 ActionContext ctx = ActionContext.getContext();
11 if (ctx != null) {
12 stack = ctx.getValueStack();
13 }
14 }
15 if (stack != null) {
16 extraContext.put(ActionContext.VALUE_STACK, valueStackFactory.createValueStack(stack));
17 }
18
19 String timerKey = "Handling request from Dispatcher";
20 try {
21 UtilTimerStack.push(timerKey);
22 String namespace = mapping.getNamespace();//从mapping对象获取命名空间
23 String name = mapping.getName(); //获取请求的action名
24 String method = mapping.getMethod(); //获取请求方法
25 //得到配置对象
26 Configuration config = configurationManager.getConfiguration();
27 //根据执行上下文参数,命名空间,名称等创建用户自定义Action的代理对象
28 ActionProxy proxy = config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
29 namespace, name, method, extraContext, true, false);
30
31 request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, proxy.getInvocation().getStack());
32
33 // if the ActionMapping says to go straight to a result, do it!
34 //如果配置文件中执行的这个action配置了result,就直接转到result
35 if (mapping.getResult() != null) {
36 Result result = mapping.getResult();
37 result.execute(proxy.getInvocation());
38 } else {
39 proxy.execute();
40 }
41
42 // If there was a previous value stack then set it back onto the request
43 if (!nullStack) {
44 request.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
45 }
46 } catch (ConfigurationException e) {
47 // WW-2874 Only log error if in devMode
48 if (devMode) {
49 String reqStr = request.getRequestURI();
50 if (request.getQueryString() != null) {
51 reqStr = reqStr + "?" + request.getQueryString();
52 }
53 LOG.error("Could not find action or result\n" + reqStr, e);
54 } else {
55 if (LOG.isWarnEnabled()) {
56 LOG.warn("Could not find action or result", e);
57 }
58 }
59 sendError(request, response, context, HttpServletResponse.SC_NOT_FOUND, e);
60 } catch (Exception e) {
61 if (handleException || devMode) {
62 sendError(request, response, context, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
63 } else {
64 throw new ServletException(e);
65 }
66 } finally {
67 UtilTimerStack.pop(timerKey);
68 }
69 }

最后通过Result完成页面跳转!

init_DefaultProperties方法加载了default.properties配置文件

init_TraditionalXmlConfigurations(); // [2]

加载了三种配置文件

struts-default.xml  只有一个

struts-plugin.xml  可能有很多个

struts.xml   只有一个

*  这三个配置文件的did一样,所以如果出现相同的选项,后者覆盖前者

*  struts2容器会在classpath环境下,及jar包下找所有的struts-plugin.xml文件

2、静态注入配置文件中标注了<bean>的类

当请求一个url时

1、执行doFilter()方法

该方法在执行过程中,首先创建actionContext,并将其放入到ThreadLocal中,通过ValueStackFactory类创建ValueStack放入到ThreadLocal中,这样做可以保证数据的安全性

2、执行Action

通过serviceAction来创建actionProxy(通过调用dispatcher中的serviceAction方法,该方法中通过在struts容器创建actionProxy实例),然后执行proxyAction中的execute()方法,最后再执行invocation.invoke()方法,在invoke()方法中,加载所有拦截器,创建Action方法,

Struts学习之流程汇总的更多相关文章

  1. Struts2学习---拦截器+struts的工作流程+struts声明式异常处理

    这一节我们来看看拦截器,在讲这个之前我是准备先看struts的声明式异常处理的,但是我发现这个声明式异常处理就是由拦截器实现的,所以就将拦截器的内容放到了前面. 这一节的内容是这样的: 拦截器的介绍 ...

  2. Dynamic CRM 2013学习笔记 系列汇总

    这里列出所有 Dynamic CRM 2013学习笔记 系列文章,方便大家查阅.有任何建议.意见.需要,欢迎大家提交评论一起讨论. 本文原文地址: Dynamic CRM 2013学习笔记 系列汇总 ...

  3. Struts 2 执行流程 配置信息

    Struts 2 执行流程 首先,浏览器访问,经过Filter,Filter从src/struts.xml中寻找命名空间和action的名字,获取action类,从方法中拿到返回值,接着从result ...

  4. ref:一系列用于Fuzzing学习的资源汇总

    ref:http://www.freebuf.com/articles/rookie/169413.html 一系列用于Fuzzing学习的资源汇总 secist2018-04-30共185833人围 ...

  5. VC++/MFC(VC6)开发技术精品学习资料下载汇总

    工欲善其事,必先利其器,VC开发MFC Windows程序,Visual C++或Visual Studio是必须的,恩,这里都给你总结好了,拿去吧:VC/MFC开发必备Visual C++.Visu ...

  6. Java虚拟机JVM学习01 流程概述

    Java虚拟机JVM学习01 流程概述 Java虚拟机与程序的生命周期 一个运行时的Java虚拟机(JVM)负责运行一个Java程序. 当启动一个Java程序时,一个虚拟机实例诞生:当程序关闭退出,这 ...

  7. Dynamic CRM 2015学习笔记 系列汇总

    这里列出所有 Dynamic CRM 2015学习笔记 系列文章,方便大家查阅.有任何建议.意见.需要,欢迎大家提交评论一起讨论. 本文原文地址:Dynamic CRM 2015学习笔记 系列汇总 一 ...

  8. java JDK8 学习笔记——助教学习博客汇总

    java JDK8 学习笔记——助教学习博客汇总 1-6章 (by肖昱) Java学习笔记第一章——Java平台概论 Java学习笔记第二章——从JDK到IDEJava学习笔记第三章——基础语法Jav ...

  9. Java前辈:学习J2EE流程中的经验和教训

    Java前辈:学习J2EE流程中的经验和教训   在这里我谈谈我在学习j2ee流程,并谈到在此过程中领会的经验和教训.以便后来者少走弯路. Java发展到现在,按应用来分主要分为三大块:J2SE,J2 ...

随机推荐

  1. dog-fooding-our-api-authentication

    Dog-fooding our API - Authentication http://blog.mirajavora.com/authenticate-web-api-using-access-to ...

  2. ASP.NET不通过添加web引用的方式调用web service接口

    尊重原著作:本文转载自http://bbs.csdn.net/topics/360223969 创建方法 //动态调用web服务 public static object InvokeWebSer(s ...

  3. 通过xib创建控制器

    什么时候才需要使用storyboard,xib,当控制器的view界面是固定死的时候,就考虑用storyboard,xib解决.      目的:让xib描述控制器view          通过xi ...

  4. @property和@synthesize

    main.m #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, cons ...

  5. poj1995-快速幂取模

    #include<iostream> #define LL long long using namespace std; //快速幂算法 LL pow(LL a,LL b,int m){ ...

  6. 【codevs】2776寻找代表元

    题目描述 Description 广州二中苏元实验学校一共有n个社团,分别用1到n编号.广州二中苏元实验学校一共有m个人,分别用1到m编号.每个人可以参加一个或多个社团,也可以不参加任何社团.每个社团 ...

  7. Intellij IDEA 2016 mybatis 生成 mapper

    转载地址:http://gold.xitu.io/entry/57763ab77db2a2005517ae3f

  8. Tomcat启动失败的解决方法

    在使用Tomcat的时候,经常会遇到启动失败的问题:解决方法:1.检查环境变量的配置,jdk的配置2.检查端口是否被占用. 关于环境变量的配置很容易搜到,如果按照网上的教程配置好了,但是还是启动失败的 ...

  9. QF——网络之网络请求的几种方式,图片缓存

    同步请求和异步请求: 同步请求会阻塞主线程:不会开启新的线程,还是主线程,所以直到请求成功后,才能执行其它操作. 异步请求不会阻塞主线程.开启新的线程去请求服务器,而不影响用户的交互操作等其他动作. ...

  10. Android GridView 二维布局界面

    GridView用于在界面上按行.列分布的方式来显示多个组件. <LinearLayout xmlns:android="http://schemas.android.com/apk/ ...