Web项目中加入struts2 的支持

  1. 在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的支持

  1. 在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" >

整合步骤:

  1. 在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的支持,并整合两者的更多相关文章

  1. Java Web学习系列——Maven Web项目中集成使用Spring、MyBatis实现对MySQL的数据访问

    本篇内容还是建立在上一篇Java Web学习系列——Maven Web项目中集成使用Spring基础之上,对之前的Maven Web项目进行升级改造,实现对MySQL的数据访问. 添加依赖Jar包 这 ...

  2. Java Web学习系列——Maven Web项目中集成使用Spring

    参考Java Web学习系列——创建基于Maven的Web项目一文,创建一个名为LockMIS的Maven Web项目. 添加依赖Jar包 推荐在http://mvnrepository.com/.h ...

  3. 在web项目中搭建一个spring mvc + spring + mybatis的环境

    介绍:本文中示范搭建一个ssm环境的框架:使用流程就是客户端通过http请求访问指定的接口,然后由服务器接受到请求处理完成后将结果返回. 本项目请求流程细节介绍:由客户端请求到指定的接口,这个接口是个 ...

  4. Web项目中加载Spring配置的常用方法

    1.web.xml中添加配置 <web-app>      <context-param>         <param-name>contextConfigLoc ...

  5. 为什么java web项目中要使用spring

    1 不使用spring的理由 spring太复杂,不利于调试. spring太复杂,不利于全面掌控代码. spring加载bean太慢. 等等. 2 对不使用spring理由的辩驳 spring io ...

  6. Axis2在Web项目中整合Spring

    一.说明: 上一篇说了Axis2与Web项目的整合(详情 :Axis2与Web项目整合)过程,如果说在Web项目中使用了Spring框架,那么又改如何进行Axis2相关的配置操作呢? 二.Axis2 ...

  7. Spring在Web项目中的三种启动加载的配置

    在最近的项目中,使用到了spring相关的很多东西,有点把spring的配置给搞混了,从网上查到的资料以及整理了一下. 在Web项目中,启动spring容器的方式有三种,ContextLoaderLi ...

  8. Spring学习(四)在Web项目中实例化IOC容器

    1.前言 前面我们讲到Spring在普通JAVA项目中的一些使用.本文将介绍在普通的Web项目中如何实例化Spring IOC容器.按照一般的思路.如果在Web中实例化Ioc容器.这不得获取Conte ...

  9. 在web项目中使用cxf开发webservice,包含spring支持

    本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...

随机推荐

  1. java经典50编程题

    菲波拉契数列:有一对兔子,从出生后第 3 个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? package com.day2; public ...

  2. 在VLFEAT中mat类型图片转换成constant float* 来进行vl_dsift_process

    How to convert an OpenCV cv::Mat into a float* that can be fed into Vlfeat vl_dsift_process: Mat mat ...

  3. php笔试题(3)--转载

    1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hello tush ...

  4. java获取classpath文件路径空格转变成了转义字符%20的问题

    java获取classpath文件路径空格转变成了转义字符%20的问题 这个问题很纠结,服务器的文件路径带有空格,空格被转化是%20了,悲剧就出现了 下面展示一段代码String path = get ...

  5. 初识ASP.NET 5中的Sake与KoreBuild

    从github上签出基于ASP.NET 5的MVC 6的源代码进行编译,发现有2个编译命令: build.cmd是针对Windows的编译命令,build.sh是针对Mac/Linux的编译命令,这本 ...

  6. 动手写一个Remoting接口测试工具(附源码下载)

    基于.NET开发分布式系统,经常用到Remoting技术.在测试驱动开发流行的今天,如果针对分布式系统中的每个Remoting接口的每个方法都要写详细的测试脚本,无疑非常浪费时间.所以,我想写一个能自 ...

  7. CentOS系统下Hadoop 2.4.1集群安装配置(简易版)

    安装配置 1.软件下载 JDK下载:jdk-7u65-linux-i586.tar.gz http://www.oracle.com/technetwork/java/javase/downloads ...

  8. Ora-01536:超出了表空间users的空间限量(转)

    Ora-01536:超出了表空间users的空间限量(转) 正在开会,同事跑过来说数据库有问题,通讯程序不能入库,赶快获取一条insert into a values()语句后在toad工具中手动插入 ...

  9. Wix 安装部署(二)自定义安装界面和行为

    上一篇介绍了如何联合MSBuild来自动生成打包文件和对WIX的一些初步认识,http://www.cnblogs.com/stoneniqiu/p/3355086.html . 这篇会在上篇的基础上 ...

  10. Devexpress GridView内嵌dx:ASPxGridLookup取得控件值乱跳解决方案

    一 页面嵌入ASPxGridLookup控件 <dx:ASPxGridView ID="gridDetail" runat="server"        ...