Struts2 Spring2 整合

Spring整合Struts2 spring整合Struts2,使得struts的action从spring中获取。login.jsp Insert title here 阅读详情

Struts2  Spring2  整合

      要实现与Struts与Spring的集成有如下几步

1.    将struts2-spring-plugin-2.0.8.jar文件包含到我们的应用中,放到WEB-INF/lib目录下面即可.

 2.配置Spring监听器.

将下面一段话插入到web.xml文件中,同时将spring.jar文件放到WEB-INF/lib目录下面。

<listener>

 

    <listener-class>

 

        org.springframework.web.context.ContextLoaderListener

 

    </listener-class>

 

</listener>

 

3.利用Spring配置文件来注册对象

     

(1)这里有一点得注意:使用spring配置文件注册action对象,

<bean>中使用 ID 来定义,class=“action包引用类名”

例如:

<bean id="registerAction" class="com.tcit.struts2.action.RegisterAction"

abstract="false" lazy-init="default" autowire="default">

</bean>

(2)     在struts.xml文件中:<action>中的class为spring

配置文件<bean>中的 ID

     <action name="register" class="registerAction" >

    <result name="success">/result.jsp</result>

</action>

 

 

 

这之后的步骤就和我们使用单独使用Spring一样了,现在我们就已经完成了 Struts与Spring的集成了。这里有一点要注意的是,我们还要指定Spring配置文件的地点,默认情况下,容器会到WEB-INF目录下面去寻 找applicationContext.xml文件。如果我们想指定别的地方的配置文件或者指定多个配置文件,可以通过在web.xml文件中定义 context-param元素来指定,如下所示:

<context-param>

 

    <param-name>contextConfigLocation</param-name>

 

    <param-value>

 

        /WEB-INF/applicationContext.xml,classpath:applicationContext-*.xml

 

    </param-value>

 

</context-param>

上面一段话表示WEB-INF下面的applicationContext.xml文件以及classpath下面的所有匹配applicationContext-*.xml模式的文件都会作为Spring配置文件被装载

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

web.xml 的源代码清单

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <!-- 用来定位Spring XML文件的上下文配置 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml,classpath*:applicationContext*.xml</param-value>
</context-param>
    
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
 
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
    <constant name="struts.objectFactory.spring.autoWire" 
    value="type" />
    <constant name="struts.objectFactory" value="spring" />
 
    <package name="default" extends="struts-default">
 
        <action name="HelloPOJO" class="helloPOJO" >
            <result>/HelloPOJO.jsp</result>
        </action>
 
    </package>
 
</struts>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans default-autowire="byType"
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    <bean id="helloPOJO" class="example.HelloPOJO" >
        <property name="message">
            <value>Spring Struts 2 注入</value>
        </property>
    </bean>
 
</beans>
 
spring2,spring3 相关技术文档 spring2,spring3 相关技术文档spring2,spring3 相关技术文档spring2,spring3 相关技术文档spring2,spring3 相关技术文档 立即下载

相关推荐

spring2

NULL 博文链接:https://hollowinheart.iteye.com/blog/1002406

在已有Struts2框架基础上整合Spring框架的相关问题

在学习struts2框架整合Spring的时候,遇到了一些问题在此总结一下,大家可以学习交流。 Problem1:Struts2中整合Spring过程(使用idea操作) (1):打开idea左上角“File”,选择“Project Structure”,选择“Modules”,选中项目XXX, 点击 + 号,选择Spring。然后,点击选中的Spring,第一次引入的时候会在右边偏下位置出现一段话,意思是没有找到相关的jar包,那么我们此时点击这段话后的蓝色部分进行Spring的jar包...

weixin_43749999的博客 793

整合struts2和spring

只使用spring和struts进行整合

strtus2改成springboot_详解如何将已有项目改造为Spring Boot项目

快速创建一个springboot web工程以IntelliJ IDEA为例:1、首先创建一个项目,创建时选择Spring Initializr,然后Next,如下图:2、填写项目信息,如下图:3、勾选web4、最后一步,填写工程名字点击finish第一次创建时系统会去下载需要的依赖,耗时稍长,请耐心等待。创建成功后,目录结构如下:项目的根目录下会有一个artifactId+Application...

weixin_39581896的博客 822

Spring2+实例

spring-framework-2.RELEASE整个的资源包,以及有一个添加用户的实例

[Github]GitHub 2FA快速安全配置全攻略

GitHub强制要求用户启用双重身份验证(2FA)以提升代码安全。本文详细介绍了2FA的三种实现方式:TOTP应用验证(推荐)、SMS短信验证(备用)和硬件安全密钥(最安全),并提供了配置指南。特别推荐使用在线工具2FA.run快速测试TOTP功能。文章还涵盖恢复代码管理、企业级2FA策略制定以及常见问题解决方案,如时间同步问题、多设备同步等。通过强制2FA、定期审计和建立安全事件响应流程,开发者可构建更安全的代码管理体系。

冰茶的博客 2618

Spring家族框架——Spring2——使用Spring进行编程

🔥本篇概览:详细讲解了Spring在编程中的详细使用,以及对上一篇文章的改编。🌈⭕🔥

做一个善良的人,做好自己的事,如果愿意,再发一份光。 1539

Keil调试技巧:3种方法查看Cortex-M4的SCB寄存器(含CPUID内存映射解析)

本文详细介绍了在Keil MDK中查看Cortex-M4内核SCB寄存器的三种实战方法:使用Watch窗口进行符号化观察、通过Memory窗口直接查看物理内存映射,以及利用SFR寄存器浏览器解析位域信息。文章重点解析了CPUID寄存器的内存映射地址(0xE000ED00)及其位域含义,帮助开发者深入理解处理器身份识别与底层调试技巧,提升嵌入式系统调试效率。

h6i7j8的博客 569

Spring和Struct2两种整合方式

Spring整合Struts2的两种方案 一、需要的JAR文件为:Spring和Struts2框架本身需要的JAR文件以及他们所依赖的JAR文件,比如commons-logging.jar等等,另外还需要Struts2发布包中的struts2-spring-plugin-x.xx.jar。二、在web.xml中增加WebApplicationContext的相应配置,以下两种配置方式本质是一样的。

jokeMqc的博客 1109

避坑指南:Livox Mid-360双雷达SLAM配置中,那些官方文档没说的细节(IP设置、话题分离与时间同步)

本文详细解析了Livox Mid-360双雷达SLAM配置中的关键优化点,包括IP设置、话题分离与时间同步等官方文档未提及的细节。通过实战案例和代码示例,帮助开发者解决点云错位、IMU数据混乱等问题,提升SLAM系统的稳定性和精度。特别针对网络架构设计、驱动修改和时间同步机制提供了专业指导。

weixin_29745609的博客 425

STM32低功耗模式下ADC采样抖动的5个隐藏陷阱及解决方案(实测避坑)

本文深入探讨了STM32低功耗模式下ADC采样抖动的5个常见陷阱及解决方案,包括多通道采样电压跃迁、外设开关信号稳定、低功耗模式与ADC时钟同步、输入阻抗失配以及基准电压稳定性问题。通过实测数据和优化代码示例,帮助工程师有效规避ADC采样数据抖动问题,提升物联网设备的测量精度和稳定性。

weixin_30316097的博客 381

spring框架与struts2框架的整合

spring与struts2的整合 1:单独配置struts 一:导入struts包 二:编写Action public class JboaEmployeeAction extends ActionSupport { public String login(){ System.out.println(“login…”); return SUCCESS; } } 三:配置struts.xml <?xml version="1.0" encoding="UTF-8" ?> i

weixin_43474701的博客 2227

ANSYS Discovery 2023R1 保姆级教程:手把手教你玩转几何模型参数化(附避坑指南)

本文提供ANSYS Discovery 2023R1几何模型参数化的全面教程,涵盖基础环境搭建、核心操作解析及高级应用场景。重点讲解参数化建模中的常见问题与避坑方案,帮助用户高效掌握Workbench与Discovery的协同使用技巧,提升工程仿真效率。

weixin_29204205的博客 752

spring整合struts2

导入依赖包:除了导入Struts2和Spring的核心库之外,还要导入commons-logging和struts2-spring-plugin包。(PS:Struts2是主导,把spring嵌到struts2中。)配置:通过配置ContextLoaderListener监听器,使容器启动时,自动加载application...

weixin_42051953的博客 276

算法面试八股文『 基础知识篇 』

个人整理的算法面试基础知识八股文,内容较详细。

SG_teresa's blog 4338

Win10安装Nek5000

1 安装wsl 2 2 安装Nek5000 3 安装依赖项 4 安装openmpi 5 配置Nek5000 6 编译Nek5000 7 运行Nek5000算例 8 安装paraview并查看结果

weixin_43176703的博客 3450

【WEB】struts2整合spring原理以及源码剖析

一、原理概述          二、实现细节 三、实现展示f

厚积薄发者,轻舟万重山 1961

WorkBuddy最新更新特性(2026-07-21)

WorkBuddy最新更新特性

AI人人懂 573

struts2+spring4+hibernate5整合实例

struts2作为一个很传统的mvc框架,在一些项目中,仍然发挥着重要的作用,另外hibernate和spring的结合也是很常见的,这里介绍struts2+hibernate5+spring4的整合,因为struts2支持最高的spring是4版本,所以这里采用的是spring4。整合的思路比较简单,可以从struts2+spring整合,然后接着整合hibernate+spring。也可以反过...

feinifi的博客 1777

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

struts2 整合spring 及 由spring治理struts的Action实例

1.当指定struts.objectFactory为spring时,struts2框架就会把bean转发给spring来创建,装配,注入。但是bean创建完成之后,还是由struts容器来治理其生命周期 2. 在某些时候,你可能希望不仅仅让SPRING创建和装配Action对象,还希望让SPRING完全治理这些对象,如希望使用AOP或者希望使用acegi时。这时候,只需要在spring的配置文件中定义这些action即可。

it_man的专栏 5379

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SSH之Spring整合struts2

Struts2+spring整合/result常用类型/拦截器 为什么?通过spring管理Struts2的组件,实现注入 怎么整合? 1.创建项目 2.导包:struts2-spring-plugin struts2-core 3.配置文件:web.xml spring-context.xml web.xml:配置struts2的filert,配置spring的启动...

weixin_30814319的博客 131

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Struts2和Spring进行整合

Struts2整合Spring,整合方式一: 动作类还是Struts2负责管理,只是向Spring容器要service的实例 0、拷贝jar包 1、搭建Spring的web环境 WEB-INF下web.xml文件 &lt;!-- web中继承Spring核心容器 --&gt; &lt;listener&gt; &lt;listener-class&gt;or...

Newstar优快云的博客 2058

Spring整合Struts2的方法

一、基本支持 通常我们整合Spring和struts2的目的是让Spring来管理struts2的控制器。也就是说把Action交由Spring来管理,利用IOC的特性把Action注入到业务逻辑中。 为此Spring提供了相应的监听器。通过注册 Servlet 监听器 ContextLoaderListener, Web 应用程序可以加载 Spring 的ApplicationContext

想作会飞的鱼的博客 642

Spring+Struts2整合

1,整合Struts2      a)导入struts的jar包          struts2-core-2.1.6.jar   xwork-2.1.2.jar  ognl-2.6.11.jar    freemarker-2.3.13.jar  commons-logging-1.1.jar  commons-fileupload-1.2.1.jar      b)将struts.xm

itmyhome的专栏 2476
上一篇: FormFile 文件上传
下一篇: struts2文件上传
jamesjun
博客等级 码龄19年 25粉丝 33原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值