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. 测试驱动 ASP.NET MVC 和构建可测试 ASP.NET MVC 应用程序

    [测试驱动 ASP.NET MVC] http://t.cn/8kdi4Wl [构建可测试 ASP.NET MVC 应用程序]http://t.cn/8kdi4Wj

  2. 监控系统Opserver

    监控系统Opserver的配置调试   Stack Exchange开源其监控系统Opserver有一段时间了.之前在项目中用过他们的MiniProfile来分析页面执行效率和帮助新人了解项目,当他们 ...

  3. C# 多线程学习总结

    C# 多线程学习总结 C#多线程学习(一) 多线程的相关概念 什么是进程? 当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.而一个进程又是由多个线程所组成的. ...

  4. [原]逆向iOS SDK -- “添加本地通知”的流程分析

    观点: 代码面前没有秘密 添加通知的 Demo 代码 - (void)scheduleOneLocalNotification { [[UIApplication sharedApplication] ...

  5. iOS 开发问题集锦(一)

    最近在QQ群里好多人问一些比较基础的问题,在这罗列一下: 1.键盘上的斜杠键坏掉了,怎么样用快捷键进行注释呢? 首先在Xcode中注释的默认快捷键为:command+/: 其次可以自行修改快捷键:Xc ...

  6. 简单好用的Adapter---ArrayAdapter

    简单好用的Adapter---ArrayAdapter 拖延症最可怕的地方就是:就算自己这边没有拖延,但对方也会拖延,进而导致自己这边也开始拖延起来!现在这个项目我这边已经是完工了,但是对方迟迟没有搞 ...

  7. img onerror事件

    怪自己知道的太少,img标签有onerror这个事件,我是才刚知道,恕我愚昧,既然是第一次遇到,而且又是一个自己从没有涉及过得的东西,所以我希望通过这个随笔来是自己印象深刻,此文仅仅只是让自己印象深刻 ...

  8. 用JSP+JavaBean开发模式实现一个销售额的查询

    数据库使用mysql,如下: vo包的Sales类: package com.vo; public class Sales {  public String salestime;  public fl ...

  9. 在OpenStack虚拟机实例中创建swap分区的一种方法

    测试组里一个同学负责MapR的搭建,MapR文档中建议每个节点上至少有24GB的swap分区,不知道MapR为啥会有这种反人类的建议……swap无非就是一块顺序读写的磁盘空间,莫非省着内存不用,用sw ...

  10. springMVC之数据传递

    在前面介绍过从controller中向页面中传数据,可以通过HttpServletRequest进行setAttribute可以将数据放入request中.并且可以在jsp页面使用el表达式获取数据. ...