spring、struts整合
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整合的更多相关文章
- spring+struts整合
首先是为什么整合strut2和spring? struts2的action是由struts2自己创建出来的,它不受spring的委托,也不受spring的管理,所以无法进行自动注入:spring和st ...
- spring+hibernate+struts整合(1)
spring+hibernate:整合 步骤1:引入类包 如下图:这里是所有的类包,为后面的struts整合考虑
- struts2,hibernate,spring整合笔记(4)--struts与spring的整合
饭要一口一口吃,程序也要一步一步写, 很多看起来很复杂的东西最初都是很简单的 下面要整合struts和spring spring就是我们的管家,原来我们费事费神的问题统统扔给她就好了 先写一个测试方法 ...
- Struts+Spring+Hibernate整合
这段笔记三两年前写的,一直因为一些琐事,或者搞忘记了,没有发.今天偶然翻出了它,就和大家一起分享下吧. 1.导入jar包 Struts的jar包: Spring的jar包: Hibernate的jar ...
- Struts、Hibernate和Spring的整合
Spring整合Hibernate Spring以其开放性,能与大部分ORM框架良好的整合.这样Spring就能轻松地使用ORM. Spring提供了DAO支持,DA0组件是应用的持久层访问的重要组件 ...
- spring和struts整合
整合准备:导入jar包 如果只是访问action,没有做数据库方面的操作的话 只需要导入下面的jar spring相关jar 以及struts相关jar包 整合过程: 用到了struts所以需要在we ...
- struts2 spring mybatis 整合(test)
这几天搭了个spring+struts2+mybatis的架子,练练手,顺便熟悉熟悉struts2. 环境:myEclipse10+tomcat7+jdk1.6(1.8的jre报错,所以换成了1.6) ...
- 【Java EE 学习 79 下】【动态SQL】【mybatis和spring的整合】
一.动态SQL 什么是动态SQL,就是在不同的条件下,sql语句不相同的意思,曾经在“酒店会员管理系统”中写过大量的多条件查询,那是在SSH的环境中,所以只能在代码中进行判断,以下是其中一个多条件查询 ...
- Spring与Struts2整合VS Spring与Spring MVC整合
Spring与Struts2整合,struts.xml在src目录下 1.在web.xml配置监听器 web.xml <!-- 配置Spring的用于初始化ApplicationContext的 ...
- struts2+hibernate-jpa+Spring+maven 整合(1)
1.0.0 struts2 与 spring 的整合. 1.1.0 新建maven工程 , 编写pom.xml ,这里只需要简单的添加 一个组件就够了: 在myeclipse 生成的pom.xml 添 ...
随机推荐
- iOS推送服务细节回顾
iOS推送服务细节回顾 之前在做推送功能时候,就总结过一系列证书的制作,OC代码实现和服务器搭建等经验.又过了一段时间了,前前后后对推送服务做了多次的完善和优化,有iOS客户端的,还有本地服务器端的. ...
- SharePoint开发
做SharePoint开发有时候是一件比较痛苦的事情,毕竟庞大的框架总是笨重的~~ 往往如果采取传统的方式开发SharePoint的话,更改一个代码需要有以下操作: 1)更改代码 2)VS编译——&g ...
- JAVA算法两道
算法(JAVA)----两道小小课后题 LZ最近翻了翻JAVA版的数据结构与算法,无聊之下将书中的课后题一一给做了一遍,在此给出书中课后题的答案(非标准答案,是LZ的答案,猿友们可以贡献出自己更快 ...
- ibatis实战之一对多关联
在实际开发中,我们常常遇到关联数据的情况,如User对象拥有若干Book对象 每个Book对象描述了归属于一个User信息,这种情况下,我们应该如何处理? 通过单独的Statement操作固然可以实现 ...
- Javascript:再论Javascript的单线程机制 之 DOM渲染时机
Javascript:再论Javascript的单线程机制 之 DOM渲染时机 背景 Javascript是单线程事件驱动的,所有能看到的Javascript代码都是在一个线程执行,定时器回调和AJA ...
- Winform程序
故事的开端是这样的,小白是一个程序员,他确实也是一个小白,目前还在程序员发展的道路上,兢兢业业的小心求学. 有一天,小白接到一个任务,完成一个Winform程序,附加一个功能就是可以读IC卡. 小白终 ...
- Socket的粘包处理
Socket的粘包处理 当socket接收到数据后,会根据buffer的大小一点一点的接收数据,比如: 对方发来了1M的数据量过来,但是,本地的buffer只有1024字节,那就代表socket需要重 ...
- Fast Token Replacement in C#
http://www.codeproject.com/Articles/298519/Fast-Token-Replacement-in-Csharp Fast Token Replacement i ...
- Web缓存解决方案
缓存是构建于HTTP统一接口之上的最有用功能之一.可以利用缓存减少终端用户感知到的延时,增加可靠性,减少带宽使用和成本,降低服务器负载.缓存无处不在,可以在服务器网络里,内容分发网络(Content ...
- HDFS中文件的压缩与解压
HDFS中文件的压缩与解压 文件的压缩有两大好处:1.可以减少存储文件所需要的磁盘空间:2.可以加速数据在网络和磁盘上的传输.尤其是在处理大数据时,这两大好处是相当重要的. 下面是一个使用gzip工具 ...