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. worker进程中线程的分类及用途

    worker进程中线程的分类及用途 欢迎转载,转载请注明出版,徽沪一郎. 本文重点分析storm的worker进程在正常启动之后有哪些类型的线程,针对每种类型的线程,剖析其用途及消息的接收与发送流程. ...

  2. Trie字典树算法

    特性 Trie树属于树形结构,查询效率比红黑树和哈希表都要快.假设有这么一种应用场景:有若干个英文单词,需要快速查找某个单词是否存在于字典中.使用Trie时先从根节点开始查找,直至匹配到给出字符串的最 ...

  3. vijos1009:扩展欧几里得算法

    1009:数论 扩展欧几里得算法 其实自己对扩展欧几里得算法一直很不熟悉...应该是因为之前不太理解的缘故吧这次再次思考,回看了某位大神的推导以及某位大神的模板应该算是有所领悟了 首先根据题意:L1= ...

  4. LevelDB架构

    LevelDB系列之整体架构   LevelDb本质上是一套存储系统以及在这套存储系统上提供的一些操作接口.为了便于理解整个系统及其处理流程,我们可以从两个不同的角度来看待LevleDb:静态角度和动 ...

  5. Struts2更改配置文件struts.xml默认路径

    struts2配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下. 但是为了协作开发与方便管理,我们有时需要把struts.xml放到其他位置 s ...

  6. hdu 1498

    每次只能消除一行或一列的相同颜色的气球, 求有多少种气球在k次内不能消除 求出每种气球最少需要多少次消除,就跟hdu 2119消除1用多少次是一样的问题 就是求有这种气球的行和列的最大匹配 #incl ...

  7. Java-继承的应用

    class array {  private int[] temp;  private int foot;  public array(int len)   //为temp数组规定大小,并开辟空间,申 ...

  8. LearnCpp.com

    LearnCpp.com is a totally free website devoted to teaching you to program in C++. Whether you’ve had ...

  9. 《Head First Python》学习笔记 01

    Python 3提供了70多个内建函数,这是Python“功能齐全”的观点:Python已经包含足够多的内置功能,使你能完成大多数工作,而不必依赖第三方代码. Python 列表: Python列表是 ...

  10. Linux 内核源码中likely()和unlikely()

    ikely()与unlikely()在2.6内核中,随处可见,那为什么要用它们?它们之间有什么区别呢? 首先明确: if (likely(value))等价于if (value)if (likely( ...