我在这里不会吃太多空间。 您可以阅读有关[**如何创建 Maven Eclipse Web 项目**](//howtodoinjava.com/maven/how-to-create-a-eclipse-web-application-using-maven/"How to create a eclipse web application using maven")的更多详细信息。 简而言之,使用以下命令。
我在这里不会吃太多空间。 您可以阅读有关[**如何创建 Maven Eclipse Web 项目**](//howtodoinjava.com/maven/how-to-create-a-eclipse-web-application-using-maven/"How to create a eclipse web application using maven")的更多详细信息。 简而言之,使用以下命令。
我在这里不会吃太多空间。 您可以阅读有关[**如何创建 Maven Eclipse Web 项目**](//howtodoinjava.com/maven/how-to-create-a-eclipse-web-application-using-maven/"How to create a eclipse web application using maven")的更多详细信息。 简而言之,使用以下命令。
我在这里不会吃太多空间。 您可以阅读有关[**如何创建 Maven Eclipse Web 项目**](//howtodoinjava.com/maven/how-to-create-a-eclipse-web-application-using-maven/"How to create a eclipse web application using maven")的更多详细信息。 简而言之,使用以下命令。
在以前的帖子中,我们了解了 [helloworld 应用](//howtodoinjava.com/struts-2/struts-2-hello-world-with-annotations/"Struts2 hello world with annotations")和[设置 Struts2 应用](//howtodoinjava.com/struts-2/how-to-correctly-set-result-path-in-struts-2/"How to correctly set result path in Struts2")的结果路径。 现在,在这篇文章中,我将举一个使用注释的自定义或用户定义的拦截器配置示例。
在以前的帖子中,我们了解了 [helloworld 应用](//howtodoinjava.com/struts-2/struts-2-hello-world-with-annotations/"Struts2 hello world with annotations")和[设置 Struts2 应用](//howtodoinjava.com/struts-2/how-to-correctly-set-result-path-in-struts-2/"How to correctly set result path in Struts2")的结果路径。 现在,在这篇文章中,我将举一个使用注释的自定义或用户定义的拦截器配置示例。
**Important**: Please note that Struts2 comes with many ready-made interceptor implementations, So make sure you really need to create your own interceptor or something can work for you.
**i)**您有一个用 Struts 编写的旧应用,并且想要使用 spring 来提高应用的功能很多倍。
**ii)**您确实想根据自己的原因来学习它。
i)您有一个用 Struts 编写的旧应用,并且想要使用 spring 来提高应用的功能很多倍。
ii)您确实想根据自己的原因来学习它。
否则,我不知道为什么有人会在 Spring 选择支柱。 如果您知道其他一些好的理由,请与我们所有人分享。 那挺棒的。
继续,在本教程中,我将**委托从 Struts 到 Spring** 进行动作管理。 进行委派的原因是,通过 Spring 上下文实例化 Action 类时,它可以使用 spring 在其自己的 MVC 实现中为其提供的 Controller 类的所有其他功能。 因此,您将获得所有 spring 功能以及 struts Action 类,以具有包括 ActionForm 概念在内的控制器逻辑。
继续,在本教程中,我将**委托从 Struts 到 Spring** 进行动作管理。 进行委派的原因是,通过 Spring 上下文实例化`Action`类时,它可以使用 spring 在其自己的 MVC 实现中为其提供的`Controller`类的所有其他功能。 因此,您将获得所有 spring 功能以及 struts `Action`类,以具有包括`ActionForm`概念在内的控制器逻辑。
## 2)Spring + Struts 集成
这是核心逻辑,从在 web.xml 中注册`ContextLoaderListener`和`StrutsPrepareAndExecuteFilter`开始。 `ContextLoaderListener`带有初始化参数 ***contextConfigLocation***,并负责设置和启动 Spring `WebApplicationContext`。 现在,struts 将在与 Spring 相关的服务中特别是在[依赖项注入](//howtodoinjava.com/spring/spring-core/inversion-of-control-ioc-and-dependency-injection-di-patterns-in-spring-framework-and-related-interview-questions/"Inversion of control (IoC) and dependency injection (DI) patterns in spring framework and related interview questions")中利用此上下文。
这是核心逻辑,从在`web.xml`中注册`ContextLoaderListener`和`StrutsPrepareAndExecuteFilter`开始。 `ContextLoaderListener`带有初始化参数`contextConfigLocation`,并负责设置和启动 Spring `WebApplicationContext`。 现在,struts 将在与 Spring 相关的服务中特别是在[依赖项注入](//howtodoinjava.com/spring/spring-core/inversion-of-control-ioc-and-dependency-injection-di-patterns-in-spring-framework-and-related-interview-questions/"Inversion of control (IoC) and dependency injection (DI) patterns in spring framework and related interview questions")中利用此上下文。
In strut’s alone application we would have full Action Class with it’s package information in “class” attribute. Here we have given the class name as editEmployeeAction. Where is it defined? We will ask Spring to lookup for us.
在单独的 strut 应用程序中,我们将在“`class`”属性中具有完整的`Action`类及其包装信息。 在这里,我们将类名命名为`editEmployeeAction`。 它在哪里定义? 我们将要求 Spring 为我们查找。
Spring 上下文文件**beans.xml**是典型的 Spring 单独上下文文件,具有 Web 应用运行所需的所有内容,其中包括 struts 正在寻找的 bean 定义`editEmployeeAction`。
Spring 上下文文件`beans.xml`是典型的 Spring 单独上下文文件,具有 Web 应用运行所需的所有内容,其中包括 struts 正在寻找的 bean 定义`editEmployeeAction`。
**beans.xml**
**`beans.xml`**
```java
<?xmlversion="1.0"encoding="UTF-8"?>
...
...
@@ -239,9 +240,9 @@ Spring 上下文文件 **beans.xml** 是典型的 Spring 单独上下文文件