struts核心工作流程与原理_第1页
struts核心工作流程与原理_第2页
struts核心工作流程与原理_第3页
struts核心工作流程与原理_第4页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、这是 Struts2 一个请求在官方站点提供的Struts 2的整体结构。Struts2框架中的处理大概分为以下几个步骤1. 客户端提起一个( HttpServletRequest)请求 , 如上文在浏览器中输入 ”就是提起一个(HttpServletRequest)请求。2.请 求被提交到一系列(主要是三层)的过滤器(Filter ),如( ActionContextCleanUp、其他过滤器( SiteMesh等)、FilterDispatcher)。注意这里是有顺序的,先ActionContextCleanUp,再其他过滤器(SiteMesh等)、最后到FilterDispatcher。

2、3. FilterDispatcher是控制器的核心, 就是 mvc 中 c 控制层的核心。 下面粗略的分析下我理解的 FilterDispatcher工作流程和原理:FilterDispatcher进行初始化并启用核心doFilter其代码如下:publicvoiddoFilter(ServletRequest req, ServletResponse res, FilterChain chain)ows IOException, ServletException HttpServletRequest request = (HttpServletRequest) req;HttpServle

3、tResponse response = (HttpServletResponse) res;ServletContext servletContext = filterConfig.getServletContext();/在这里处理了HttpServletRequest和 HttpServletResponse。DispatcherUtils du = DispatcherUtils.getInstance();du.prepare(request, response);/ 正如这个方法名字一样进行locale、 encodingthr以及request parameterstryrequ

4、est = du.wrapRequest(request, servletContext);/ 对catch(IOException e) String message = Could not wrap servlet request with MultipartRequestWrapper!;LOG.error(message, e);thrownewServletException(message, e);request进行包装ActionMapperIF mapper = ActionMapperFactory.getMapper();action的 mapperActionMappin

5、g mapping = mapper.getMapping(request);/得到action的 mappingif (mapping =null ) / 得到/ there is no action in this request, should we look for a static resource? String resourcePath = RequestUtils.getServletPath(request);if (.equals(resourcePath) & null != request.getPathInfo() resourcePath = request.get

6、PathInfo();if (true.equals(Configuration.get(WebWorkConstants.WEBWORK_SERVE_STATIC_CONTENT)& resourcePath.startsWith(/webwork) String name = resourcePath.substring(/webwork.length();findStaticResource(name, response);else / this is a normal request, let it pass through chain.doFilter(request, respon

7、se);/ WW did its job here return ;Object o =trynull ;/setupContainer(request);o = beforeActionInvocation(request, servletContext);/ 整个框架最最核心的方法,下面分析du.serviceAction(request, response, servletContext, mapping);finally afterActionInvocation(request, servletContext, o);ActionContext.setContext(null );d

8、u.serviceAction(request, response, servletContext, mapping);/ 这个方法询问 ActionMapper是否需要调用某个 Action 来处理这个( request )请求,如果ActionMapper决定需要调用某个Action,FilterDispatcher把请求的处理交给ActionProxypublicvoidserviceAction(HttpServletRequest request, HttpServletResponse response, String namespace, String actionName, M

9、ap requestMap, Map parameterMap, Map sessionMap, Map applicationMap) HashMap extraContext = createContextMap(requestMap, parameterMap, sessionMap, applicationMap, request, response, getServletConfig();/ 实例化Map请求 ,询问ActionMapper是否需要调用某个Action来处理这个(request)请求extraContext.put(SERVLET_DISPATCHER,this );

10、OgnlValueStack stack = (OgnlValueStack) request.getAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY);if (stack !=null ) extraContext.put(ActionContext.VALUE_STACK,new OgnlValueStack(stack);tryActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy(namespace, actionName, extraConte

11、xt);/ 这里交给actionName ActionProxy是通过两道getActionName,下面是ServletDispatcher解析出来的的 TODO:, FilterDispatcher把请求的处理request.setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, proxy.getInvocation().getStack();proxy.execute();/ 通过代理模式执行ActionProxyif (stack !=null )request.setAttribute(ServletActionConte

12、xt.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,

13、e);4.FilterDispatcher询问 ActionMapper是否需要调用某个Action来处理这个( request请求, 如果 ActionMapper决定需要调用某个Action ,FilterDispatcher把请求的处理交给 ActionProxy。)5.ActionProxy通过Configuration Manager( struts.xml)询问框架的配置文件,找到需要调用的Action类 .如上文的struts.xml配置 add.jsp 如果提交请求的是add.action,那么找到的Action类就是edisundong.AddAction。6.ActionP

14、roxy创建一个ActionInvocation的实例,同时ActionInvocation通过代理模式调用 Action 。但在调用之前ActionInvocation会根据配置加载Action相关的所有Interceptor。( Interceptor是 struts2另一个核心级的概念)下面我们来看看ActionInvocation是如何工作的:ActionInvocation是Xworks中Action调度的核心。 而对Interceptor的调度, 也正是由ActionInvocation负责。ActionInvocation是一个接口,而DefaultActionInvocatio

15、n则是Webwork对ActionInvocation的默认实现。Interceptor的调度流程大致如下:1. ActionInvocation初始化时,根据配置,加载Action相关的所有Interceptor。2. 通过ActionInvocation.invoke方法调用Action实现时,执行Interceptor。Interceptor将很多功能从我们的Action中独立出来,大量减少了我们Action的代码,独立出来的行为具有很好的重用性。XWork、 WebWork的许多功能都是有 Interceptor实现,可以在配置文件中组装Action用到的 Interceptor,它会

16、按照你指定的顺序,在Action执行前后运行。那么什么是拦截器。拦截器就是AOP ( Aspect-Oriented Programming)的一种实现。(AOP 是指用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作。)拦截器的例子这里就不展开了。struts-default.xml文件摘取的内容:7.一旦 Action执行完毕, ActionInvocation负责根据struts.xml中的配置找到对应的返回结果。如上文中将结构返回“add.jsp ”,但大部分时候都是返回另外一个action ,那么流程又得走一遍 Struts2/XWork远程命令执行漏洞POC201

17、0-12-04struts2 一种的框架技术,和传统的struts1 有很大的改进。struts2=struts +WebWork 。WebWork 是由 OpenSymphony 组织开发的,致力于组件化和代码重用的拉出式模式 J2EE Web 框架。WebWork目前最新版本是 2.1 ,现在的 WebWork2.x 前身是 Rickard Oberg 开发的 WebWork ,但现在 WebWork 已经被拆分成了 Xwork1 和 WebWork2两个项目。 XWork 是一个标准的 Command 模 式实现,并且完全从 web 层脱离出来。Xwork 提供了很多核心功能:前端拦 +

18、 截器( interceptor ),运行时表单属性验证,类型转换,强大的表达式语言 ( OGNL the Object GraphNavigation Language ), IoC (Inversion of Control倒置控制)容器等。其目的是:创建一个泛化的、可重用且可扩展的命令模式框架,而不是一个特定在某个领域使用的框架。XWork 存在远程命令执行。+info:Friday, July 9, 2010CVE-2010-1870: remote command execution+poc:Actual proof of concept had to use OGNL s expression evaluationwhen crafting HTTP request. PoC for this bug will be published onJuly 12 2010. To test whether your application is vulnerable you can use the following proof of con

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论