web项目中加入struts2、spring的支持,并整合两者
Web项目中加入struts2 的支持
- 在lib下加入strut2的jar包
2. 在web.xml中添加配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
3. 在src下添加 struts2的配置文件
Web项目中添加spring的支持
- 在lib下加入spring.jar
2. 在web.xml中添加spring的配置信息
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
3. 在src下加入spring的配置文件
在web项目中整合struts2和spring(个人认为是代码最优的一种方式)
l Action由struts2创建
<action name="showname"
class="net.wanggd.mobile_scm.test.action.TestAction">
l struts2中用到的spring中的bean有spring自动注入
1. struts的配置文件default.properties文件由如下配置struts.objectFactory.spring.autoWire = name
2. spring的配置文件中有
<beans 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.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName" >
整合步骤:
- 在lib下加入插件
2. Struts.xml中配置的内容的写法和没有引入spring之前的写法一样,不用变
<?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.action.extension" value="do" />
<constant name="struts.devMode" value="false" />
<package name="default" namespace="/" extends="struts-default">
<action name="welcome">
<result>/WEB-INF/jsp/MyJsp.jsp</result>
</action>
<action name="showname"
class="net.wanggd.mobile_scm.test.action.TestAction">
<result name="ret">/WEB-INF/jsp/index2.jsp</result>
</action>
</package>
</struts>
3. Spring的配置文件写法
<?xml version="1.0" encoding="UTF-8"?>
<beans 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.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName" >
<bean id="testService"
class="net.wanggd.mobile_scm.test.service.TestServiceImpl" >
</bean>
</beans>
Web项目中配置文件在src下面
当部署到tomcat下后,src下面的东西会自动出现在classpath下面
web项目中加入struts2、spring的支持,并整合两者的更多相关文章
- Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问
本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...
- Java Web学习系列——Maven Web项目中集成使用Spring
参考Java Web学习系列——创建基于Maven的Web项目一文,创建一个名为LockMIS的Maven Web项目. 添加依赖Jar包 推荐在http://mvnrepository.com/.h ...
- 在web项目中搭建一个spring mvc + spring + mybatis的环境
介绍:本文中示范搭建一个ssm环境的框架:使用流程就是客户端通过http请求访问指定的接口,然后由服务器接受到请求处理完成后将结果返回. 本项目请求流程细节介绍:由客户端请求到指定的接口,这个接口是个 ...
- Web项目中加载Spring配置的常用方法
1.web.xml中添加配置 <web-app> <context-param> <param-name>contextConfigLoc ...
- 为什么java web项目中要使用spring
1 不使用spring的理由 spring太复杂,不利于调试. spring太复杂,不利于全面掌控代码. spring加载bean太慢. 等等. 2 对不使用spring理由的辩驳 spring io ...
- Axis2在Web项目中整合Spring
一.说明: 上一篇说了Axis2与Web项目的整合(详情 :Axis2与Web项目整合)过程,如果说在Web项目中使用了Spring框架,那么又改如何进行Axis2相关的配置操作呢? 二.Axis2 ...
- Spring在Web项目中的三种启动加载的配置
在最近的项目中,使用到了spring相关的很多东西,有点把spring的配置给搞混了,从网上查到的资料以及整理了一下. 在Web项目中,启动spring容器的方式有三种,ContextLoaderLi ...
- Spring学习(四)在Web项目中实例化IOC容器
1.前言 前面我们讲到Spring在普通JAVA项目中的一些使用.本文将介绍在普通的Web项目中如何实例化Spring IOC容器.按照一般的思路.如果在Web中实例化Ioc容器.这不得获取Conte ...
- 在web项目中使用cxf开发webservice,包含spring支持
本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...
随机推荐
- 4.20-4.24程序设计基础结束,UID课程
通过其他方式实现string函数的效果,效果有比较数组字符.显示字符串长度.复制字符串等.在比较字符串的时候,首先是比较字符串的长度,当长度一样的时候进行不同位置上一一对应的字符比较大小.关于字符长度 ...
- 安装Pomelo 时遇到的坑
一.Pomelo相关的代码地址 https://github.com/NetEase,这里面包含比较多的项目. 2. https://github.com/NetEase/pomelo/wiki/%E ...
- 数据库知识整理<二>
又继续写的博客,希望自己能坚持每天写博客.分享自己的点滴,对自己成长有帮助.今天下午高强度打了三个小时篮球,小腿都抽筋了.很爽,失落的心情似乎变得开明了一些.想到了一句话:“像SB式的坚持总会有好的收 ...
- [Windows-Linux]Windows and Linux 共享文件
在 windows 上共享一个文件夹 共享操作很简单就不多熬述,不过要注意权限分配问题.我们假定共享了 E:\Develop\Share 这个目录. 我们假设主机局域网的 IP 为 192.168.0 ...
- Address already in use: bind
Eclipse中报了这个错误,下拉小窗口,可以看到正在运行的项目,选中项目,都关闭就Ok了 还有一种方法就是关闭javaw.exe进程
- word2vec模型原理与实现
word2vec是Google在2013年开源的一款将词表征为实数值向量的高效工具. gensim包提供了word2vec的python接口. word2vec采用了CBOW(Continuous B ...
- 说不尽的MVVM(3) – 从通知属性说起
上篇我们体验了一个从事件处理程序到MVVM程序的转变,在最后也留下了一个问题:RaisePropertyChanged的原理是什么?今天我们来一探究竟. 通过上节做的小例子我们知道,仅仅修改ViewM ...
- AdaBoost算法简介
一.AdaBoost的损失函数 AdaBoost优化的是指数损失,即\begin{align*} \mathbb{E}_{\boldsymbol{x} \sim \mathfrak{D}, y}[e^ ...
- linxu ffmpeg 编译安装
1.下载ffmpeg. 下载网址:http://www.ffmpeg.org/download.html 2.解压缩 tar -zxvf ffmpeg-2.0.1.tar.gz 3.配置,生成Make ...
- Atitit. BigConfirmTips 控件 大数据量提示确认控件的原理and总结O9
Atitit. BigConfirmTips 控件 大数据量提示确认控件的原理and总结O9 1. 主要的涉及的技术 1 2. 主要的流程 1 3. 调用法new confirmO9t(); 1 4. ...