深入解析Struts2内核:从FilterDispatcher到ActionInvocation

4星 · 超过85%的资源 需积分: 10 4 下载量 50 浏览量 更新于2024-07-29 收藏 300KB PDF 举报
"Struts2_内核中文文档.pdf" Struts2是一个强大的MVC(Model-View-Controller)框架,其设计灵感来源于WebWork框架,并且为了保持与Struts1的兼容性,它在很多方面沿用了Struts1的编码习惯。然而,Struts2的核心控制器与Struts1有很大不同,它不再是一个Servlet,而是变成了一个过滤器——`org.apache.struts2.dispatcher.FilterDispatcher`。这种改变使得Struts2能够更好地适应现代Web应用的需求,提供了更灵活的请求处理和拦截机制。 在Struts2的工作流程中,初始请求会经过一系列的标准过滤器链,这些过滤器可能包括用于清理ActionContext的`ActionContextCleanUp`过滤器,以支持与其他技术如SiteMesh的集成。过滤链中的主角`FilterDispatcher`负责解析请求,通过`ActionMapper`来判断该请求是否需要映射到一个特定的Action。 如果`ActionMapper`确认需要调用Action,`FilterDispatcher`就会将控制权传递给`ActionProxy`。`ActionProxy`是整个流程的关键组件,它根据配置文件(通常是struts.xml)来决定应该执行哪个Action类。这一步骤允许框架动态地决定Action的执行,增强了框架的灵活性。 `ActionProxy`创建一个`ActionInvocation`的实例,`ActionInvocation`是执行Action的实体。在调用Action之前,`ActionInvocation`会按照配置的拦截器链顺序执行拦截器。拦截器可以用来实现诸如登录检查、日志记录、事务管理等跨Action的功能,极大地提高了代码的复用性和可维护性。 在所有拦截器执行完毕后,`ActionInvocation`会实际调用Action的execute方法。Action执行完成后,结果会被返回,`ActionInvocation`再次利用`ActionMapper`来决定如何将控制权传递给结果,这通常涉及到视图的渲染。视图可能是JSP、FreeMarker模板或者其他类型的视图技术。 整个流程的官方工作流程图清晰地展示了这些步骤,从过滤器链的开始,经过ActionMapper、ActionProxy,再到ActionInvocation和结果处理,最后呈现给用户。通过深入理解Struts2的内核,开发者可以更有效地调试和优化应用程序,提高开发效率。 学习Struts2内核的源码,不仅可以帮助开发者理解框架的工作原理,还可以在遇到问题时提供直接的解决方案。对于新手来说,可能会觉得有些复杂,但随着实践经验的积累,会对这些概念有更深入的理解。同时,分享和讨论这些知识也是促进技术成长的重要方式。 Struts2内核中文文档是初学者和有经验的开发者都值得参考的资源,它详尽地解释了Struts2的核心机制,有助于提升对Struts2框架的掌握。通过学习文档并动手实践,可以更深入地理解框架的每一个环节,从而更好地运用在实际项目中。

192.168.85.1 - - [26/Jun/2022:06:07:07 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 24 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 12925 192.168.85.1 - - [26/Jun/2022:06:07:11 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 200 14 192.168.85.1 - - [26/Jun/2022:06:08:06 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 15 192.168.85.1 - - [26/Jun/2022:06:08:16 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 1227 192.168.85.1 - - [26/Jun/2022:06:10:15 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 79 192.168.85.1 - - [26/Jun/2022:06:13:25 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 404 752 192.168.85.1 - - [26/Jun/2022:06:16:42 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:16:57 -0400] "GET //struts2-showcase/hhh.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:18:55 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:19:02 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 35 192.168.85.1 - - [26/Jun/2022:06:19:09 -0400] "GET //struts2-showcase/hhh1.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:19:34 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 400 192.168.85.1 - - [26/Jun/2022:06:20:37 -0400] "POST /struts2-showcase/index.action HTTP/1.1" 500 5 192.168.85.1 - - [26/Jun/2022:06:20:42 -0400] "GET //struts2-showcase/hhh1.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:20:46 -0400] "GET //struts2-showcase/hhh.jsp HTTP/1.1" 403 642 192.168.85.1 - - [26/Jun/2022:06:20:51 -0400] "GET /struts2-showcase/hhh.jsp HTTP/1.1" 403 642

2023-07-12 上传

我用Spring5的aop应用时报这个错误Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\ecliple\web5\WEB-INF\applicationContext.xml]; nested exception is java.nio.file.NoSuchFileException: WEB-INF\applicationContext.xml,他说我的applicationContext.xml文件不存在,可是我明明有这个文件,另外我的web.xml需要更改吗<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <context-param> <param-name>contextConfigLocation </param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <display-name>Struts2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>

2023-05-30 上传