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 ...
随机推荐
- C语言和Lua的交互
//test.c #include <stdio.h> #include "lua.h" #include "lualib.h" #include ...
- SpringMVC上传文件
SpringMVC中上传文件还是比较方便的,Spring内置了一些上传文件的支持类,不需要复杂的操作即可上传文件. 文件上传需要两个jar支持,一个是commons-fileupload.jar和co ...
- office2003-2007 绿色版 出错 文件丢失(未解决)
- 这个版本是我大学时候(2012)年一直用到现在的版本:目录结构如下: 原来一直在32位系统中使用,没有出错过; - 刚装的两台电脑系统分别为 Win7Pro 和 Win10Pro ,都是64位的: ...
- 【5_283】Move Zeroes
终于碰到一道水题,睡觉去~ Move Zeroes Total Accepted: 37369 Total Submissions: 88383 Difficulty: Easy Given an a ...
- 日期运算 jsf日期组建
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date; try { d ...
- git clone 错误ca-certificates.crt
git clone https://github.com/baoyiluo/selfblog.git Cloning into 'selfblog'... error: server certific ...
- C++中复制构造函数
复制构造函数 复制构造函数用于: 根据另一个同类型的对象显示或隐式初始化一个对象 复制一个对象,将它作为实参传给一个函数 从函数返回时复制一个对象 初始化顺序容器中的元素 根据元素初始化式列表初始化数 ...
- 快速创建node应用[Express框架]
安装Express npm install -g express 建立工程 express -e ejs FaceExpresscd FaceExpress && npm instal ...
- centos7 配置vnc
这是一个关于怎样在你的 CentOS 7 上安装配置 VNC 服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置 VNC ...
- 125 Valid Palindrome
public class Solution { public boolean isPalindrome(String s) { if(s==null) return false; s=s.toLowe ...