package com.hanqi.test;

public class JISQ {

	public double add(double a,double b)
{
return (a+b);
} }

  

package com.hanqi.test;

public class TestDAO {
//数据连接
private String conn; public String getConn() {
return conn;
} public void setConn(String conn) {
this.conn = conn;
} public String getname()
{
return "得到连接="+conn+"并嗲用了DAO";
} }
package com.hanqi.test;

public class TestService {

	private TestDAO ts;
public TestDAO getTs() {
return ts;
}
public void setTs(TestDAO ts) {
this.ts = ts;
}
public String getDAOname()
{
//TestDAO td=new TestDAO();
return ts.getname(); }
}

  

package com.hanqi.test;

public class TestAction
{
private TestService ts7;
public TestService getTs7() {
return ts7;
}
public void setTs7(TestService ts7) {
this.ts7 = ts7;
}
public String test1()
{
//TestService ts=new TestService();
System.out.println(ts7.getDAOname());
return "success";
} }

  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"> <bean id="jsq" class="com.hanqi.test.JISQ"></bean> <!--Action类的实例不能是单例的 -->
<bean id="test2" class="com.hanqi.test.TestAction" scope="prototype"></bean> <bean id="testDAO" class="com.hanqi.test.TestDAO"> <property name="conn" value="Oracle"></property> </bean>
<bean id="testService" class="com.hanqi.test.TestService">
<property name="ts" ref="testDAO"></property>
</bean>
<bean id="testID" class="com.hanqi.test.TestAction">
<property name="ts7" ref="testService"></property> </bean> </beans>

  

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- 设置过滤的扩展名 -->
<constant name="struts.action.extension" value="action,do,,"></constant>
<!-- 允许调用静态方法和静态属性 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
<!-- 定义包 -->
<package name="test" extends="struts-default">
<action name="testform" class="testID" method="test1">
<result>view.jsp</result>
</action> </package>
</struts>

  

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Test39</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- spring有关的 --> <!-- 配置文件 -->
<!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:app.xml</param-value>
</context-param> <!-- Bootstraps the root web application context before servlet initialization -->
<!-- 把Spring容器放到全局对象中 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 过滤器 -->
<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>/*</url-pattern>
</filter-mapping> </web-app>

  

<%@page import="com.hanqi.test.JISQ"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
测试 <%
//调用spring容器的bean的实例 //加载容器 通过什么途径
WebApplicationContext ac=
WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); JISQ jsq=ac.getBean(JISQ.class); %>
<br>
123+456=<%=jsq.add(123, 456)%> <br><br>
<a href="testform">发起请求</a>
</body>
</html>

  

spring、struts整合的更多相关文章

  1. spring+struts整合

    首先是为什么整合strut2和spring? struts2的action是由struts2自己创建出来的,它不受spring的委托,也不受spring的管理,所以无法进行自动注入:spring和st ...

  2. spring+hibernate+struts整合(1)

    spring+hibernate:整合 步骤1:引入类包 如下图:这里是所有的类包,为后面的struts整合考虑

  3. struts2,hibernate,spring整合笔记(4)--struts与spring的整合

    饭要一口一口吃,程序也要一步一步写, 很多看起来很复杂的东西最初都是很简单的 下面要整合struts和spring spring就是我们的管家,原来我们费事费神的问题统统扔给她就好了 先写一个测试方法 ...

  4. Struts+Spring+Hibernate整合

    这段笔记三两年前写的,一直因为一些琐事,或者搞忘记了,没有发.今天偶然翻出了它,就和大家一起分享下吧. 1.导入jar包 Struts的jar包: Spring的jar包: Hibernate的jar ...

  5. Struts、Hibernate和Spring的整合

    Spring整合Hibernate Spring以其开放性,能与大部分ORM框架良好的整合.这样Spring就能轻松地使用ORM. Spring提供了DAO支持,DA0组件是应用的持久层访问的重要组件 ...

  6. spring和struts整合

    整合准备:导入jar包 如果只是访问action,没有做数据库方面的操作的话 只需要导入下面的jar spring相关jar 以及struts相关jar包 整合过程: 用到了struts所以需要在we ...

  7. struts2 spring mybatis 整合(test)

    这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...

  8. 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】

    一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...

  9. Spring与Struts2整合VS Spring与Spring MVC整合

    Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...

  10. struts2+hibernate-jpa+Spring+maven 整合(1)

    1.0.0 struts2 与 spring 的整合. 1.1.0 新建maven工程 , 编写pom.xml ,这里只需要简单的添加 一个组件就够了: 在myeclipse 生成的pom.xml 添 ...

随机推荐

  1. Robots惊恐记

    昨天发现在百度上搜索不到网站krely.cn的关键词(季小鱼),我记得之前的排名是第四位.到底是哪里的错误导致这个问题呢. 百度排名丢失,那么360会不会也出现同样的错误呢. 可以看到,360提示是我 ...

  2. [RM 状态机详解3]RMContainer状态机详解

    摘要 RMContainer是RM内部维护的Container状态.事实上,在RM的调度器中,会维护着一个liveContainers列表,保存着所有存活着的Container信息.图1显示RMCon ...

  3. [转]ARM Pipeline

    Add r0, PC, # g_oalAddressTable - (+ 8) instruction, a lot of people had cprogramdev.com Forum asked ...

  4. jQuery extend函数详解

    一 jQuery的扩展方法原型是 $.extend(dest,src1,src2,src3); 含义是将src1,src2,src3合并到dest中,返回值为合并后的dest,该方法合并后,dest的 ...

  5. 随机生成n个不相等的随机数

    在计算机视觉中,(例如8点算法)经常用到RANSAC算法在N个数据中找到最合适的一组n(n<N)个数据对,使某项指标达到最大.解决这个问题需要随机的在N个数据对中采样.本文实现一种线性的,复杂度 ...

  6. 关于socket通讯,如何才能高效?

    关于socket通讯,如何才能高效? 网络通讯,一个不朽的话题,今天和一个做游戏的朋友(以前的同事聊天),他向我诉说了他的痛苦 他之前是做客户端的,无奈人力资源紧张,也开始搞服务器,他说自己的服务器总 ...

  7. SQL拼接方法

    smark Beetle可靠.高性能的.Net Socket Tcp通讯组件 另类SQL拼接方法 在编写SQL的时候经常需要对SQL进行拼接,拼接的方式就是直接String+处理,但这种情况有个不好的 ...

  8. 虚拟化平台cloudstack新版本的调试

    虚拟化平台cloudstack(7)——新版本的调试 调试环境 ubuntu 12.04 JDK1.7 apache-maven-3.10 eclipse 4.2 Juno mysql 5 源码下载及 ...

  9. opencv编程入门技巧

    opencv编程入门技巧 最近在项目中负责图像处理模块的编程工作,主要分为两个板块,一是视频图像去雾,二是可视.红外图像融合.为了提升开发效率,遂开始学习并使用opencv图像类库,效果很好的说~因为 ...

  10. CentOS常用到的查看系统命令

    CentOS常用到的查看系统命令   # uname -a    # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue   # 查看操作系统版本 # cat /proc/c ...