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. Model层数据验证

    问题1:View层如何向Controller的Action传递Model数据?在View中,可以使用Form表单进行模型数据的提交,同样的,我们需要关联提交数据的类型,则需要在View中使用@mode ...

  2. windows7 自带l2tp/ipsec VPN客户端连接Cisco ASA

    搞了半天,最后发现其实很简单,在ASA默认配置的基础上,把所有crypto ipsec ikev1 transform-set 加上mode transport,然后把tunnel-group Def ...

  3. hibernate 不识别union解决方法

    问题: 一个表里有  1, 2           1, 3           2, 1           2, 4  现在要找第一位是1的第二位:2,3 和 第二位是1的第一位:2.然后去掉重复 ...

  4. 转发 eclipse 取消javascript 验证

    博客地址: http://blog.csdn.net/itchiang/article/details/7498474 最近出了一个很怪的现象,某一个js文件,在某一个Eclipse工程中呆的好好的, ...

  5. line-height,vertical-align及图片居中对齐问题根源解析

    关于图片居中对齐的问题,进入前端行业虽然有一段时间了,以为自己懂了,可是实际上还是一知半解,找了一些博客来看了一下,但是感觉讲的有点碎,看完还是一知半解. 查阅了一下<css权威指南>,结 ...

  6. [DNX]解决dnu restore时找不到Newtonsoft.Json的问题

    在Mac上用最新版的dnx 1.0.0-beta5-11855进行dnu restore,出现下面的错误: System.IO.FileNotFoundException: Could not loa ...

  7. 初学者利用git 上传代码到Coding的简单操作步骤

    1.首先登陆coding网站注册账号https://coding.net/ (注册完后需登陆邮箱激活邮件) 2.登陆刚注册的coding账号 ,添加项目 添加项目—〉输入项目名称—〉输入对项目的简单描 ...

  8. DDD领域驱动设计之运用层代码

    1.DDD领域驱动设计实践篇之如何提取模型 2.DDD领域驱动设计之聚合.实体.值对象 3.DDD领域驱动设计之领域基础设施层 4.DDD领域驱动设计之领域服务 5.整体DEMO代码 什么是运用层,说 ...

  9. [stm32] 利用uC-BmpCvt软件生成uc-gui可调用的bmp图片

    >_<:学习贴图[bmp图]:首先找一张bmp格式的图片,然后下载uC-BmpCvt软件,打开改图片 >_<:然后点击Image-Conver-Into-Best Palatt ...

  10. java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

    这个错误错了几次,必须做个标记 解决方法非常的简单: 最新的19版本会在你的项目下建立一个依赖包 Android Dependencies,在eclipse中右键这个文件夹,在Build Path选项 ...