`

写了一个hello world 出错了

DWR 
阅读更多

直接贴代码吧

1.jsp的代码

	<script type="text/javascript" src="<%=base %>/dwr/util.js"></script>
	<script type="text/javascript" src="<%=base %>/dwr/engine.js"></script>
	<script type="text/javascript" src="<%=base %>/js/jquery-1.4.min.js"></script>
	<script type="text/javascript" src="<%=base %>/dwr/interface/databaseRemoteService.js"></script>
	
	<script type="text/javascript">
		
		function ValidateConnection()
		{
		 
			var DatabaseModel = {driverName:null,url:null,userName:null,password:null};
			dwr.util.getValues(DatabaseModel);
			databaseService.validateConnection(DatabaseModel,function(flg){
				if(flg==true){
				 alert("连接成功了");
				}
				else{ alert("连接错误了");}
			});
		}
	
	
	</script>

 

 

2.dwr.xml

 

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr"
	xsi:schemaLocation="
		     http://www.springframework.org/schema/beans 
		     http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	         http://www.directwebremoting.org/schema/spring-dwr
	         http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd"
	         default-autowire="byName">
	<dwr:configuration>
		<dwr:convert type="bean" class="com.dexs.model.DatabaseModel"></dwr:convert>
	</dwr:configuration>


	<bean id="databaseService" class="com.dexs.service.impl.DatabaseServiceImpl">
		<dwr:remote javascript="databaseRemoteService">
			<dwr:include method="validateConnection"/>
		</dwr:remote>
	
	</bean>

 3.web.xml

 

 

  	<!--  配置 dwr servlet-->
 

 
	<servlet>
		<servlet-name>dwr-invoker</servlet-name>
		<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
		<load-on-startup>3</load-on-startup>
	</servlet>


	<servlet-mapping>
		<servlet-name>dwr-invoker</servlet-name>
		<url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
 


</web-app>

   4.daoimpl.java

 

/**验证数据库连接
	 * 
	 * return boolean
	 */
	@Override
	public boolean validateConnection(DatabaseModel connectionDbModel) {
		// TODO Auto-generated method stub
		boolean  flg = false;
		Connection conn = null;
		
		if(connectionDbModel != null){
		 
		try {
	Class.forName(connectionDbModel.getDriverName());
	try {
		DriverManager.getConnection(connectionDbModel.getUrl(), connectionDbModel.getUserName(),connectionDbModel.getPassword());
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	finally{
	 
		 if(conn!=null)
		 {
			 try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
	}
			
			return true;
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		
		return flg;
		
		
	
	}

 

 

 

 

分享到:
评论

相关推荐

    spring-security helloWorld入门实例

    spring-security helloWorld入门实例,其实就是个配置文件,jar包一致,否则出错

    Qt Creator 的安装和hello world 程序+其他程序的编写--不是一般的好

    后打开另一个窗口,一个是打开另一个窗口而自身不消失。可以看到他们实现的 方法是不同的。 三、Qt Creator 登录对话框(原创) 实现功能: 在弹出对话框中填写用户名和密码,按下登录按钮,如果用户名和密码均正确...

    esp_hello_world:原生ESP8266 SDK的第一步

    esp_hello_world 原生ESP8266 SDK的第一步(使用Sming框架) 变更日志:31.05.15 我们有更新日志要构建WebGui,我们需要Node.js,转到项目文件夹,运行npm install(once),并在每次更改Webgui文件时键入grunt 我们...

    ArduinoCode1-让Arduino说出HelloWorld.ino

    此为Arduino基础教程,第一节实验时所用代码。跟随教程进行自我学习的同学,若对代码和Arduino编程环境不够熟悉的同学,可采取直接下载编程代码的方式,进行实验的练习和探索。

    以太坊:以太坊开发HelloWorld for Java

    以太坊开发HelloWorld for Java :grinning_face_with_smiling_eyes:更新版本,支持插件。Geth下载官方下载: : 国内知名: ://ethfa​​ns.org/wikis/Ethereum-Geth-Mirror其他安装方式: : ***** CentOS *****$ yum...

    python第一课-认识python.doc

    Python 第一课 认识python 一、简单的Python程序 对于大多数程序语言,第一个入门编程代码便是 "Hello World!", 以下代码为使用 Python 输出 "Hello World!": 实例: #!/usr/bin/python print("Hello, World!") ...

    系统学习TCL脚本入门教程

    不过关于tcl的资料多而杂,一时心血来潮,想到写一篇文章,以例子为中心,系统讲解tcl语法,让技术人员花最少的时间对tcl有个全面而系统的了解,工作上使用时可以速查或参考代码。于是有了本文。 1.2 运行环境 多数...

    HELLO_WORLD

    这是HELLO WORLD(CS 161)的仓库可用脚本克隆仓库: git clone https://github.com/prazolpp/HELLO_WORLD.git 安装前端和后端依赖项: 转到前端仓库并运行: npm run install 。 转到后端仓库并运行: npm run ...

    as3代码生成库ClsCreator.zip

    ClsCreator 是一个中文的as3代码生成库, 以非常oo, 迅捷, 自动的方式生成需要的代码, 忘掉容易出错, 可维护性又差的模板生成方式吧 hello world  var cls:Cls = new Cls("HelloWorld", new Pack("")...

    Android程序员入门(中文版).doc

    在CLI中创建一个图片基础的Hello World! 第六章(14) 52 第七章 使用Intents 和电话拨号盘 53 使用Intents 和电话拨号盘 第七章(1) 53 Intents是什么? 第七章(2) 53 使用拨号盘 第七章(3) 58 从你的活动中打出电话...

    中文版Android程序员入门

    在CLI中创建一个图片基础的Hello World! 第六章(14) 52 第七章 使用Intents 和电话拨号盘 53 使用Intents 和电话拨号盘 第七章(1) 53 Intents是什么? 第七章(2) 53 使用拨号盘 第七章(3) 58 从你的活动中打出电话...

    班级布置学习C#课程的第一天

    第一个C#语言的设计的名字COOL 2000.2更名为C# 与C++同化加上一些时髦的语言特 性是java打击的对象也是微软的 主要开发工具 C#的优点: 1、安全 稳定 简单 优雅 2、创新的语言特性 3、面向对象组件编程支持 ...

    android开发指南

    在CLI中创建一个图片基础的Hello World! 第六章(14) 44 第七章 使用Intents 和电话拨号盘 44 使用Intents 和电话拨号盘 第七章(1) 44 Intents是什么? 第七章(2) 45 使用拨号盘 第七章(3) 49 从你的活动中打出电话...

    linux驱动学习去开发入门

    一个学习Linux设备驱动程序都会碰到的第一个例程: #include #include &lt;linux/module.h&gt; MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void) { printk(KERN_ALERT "Hello, Tekkaman Ninja !\n"); ...

    Eclipse3.2绿色中文版无需安装

    这是一个端到端教程,用于说明如何创建插件、定义基于插件的产品、定制产品、导出 RCP 应用程序和定义基于功能部件的产品 通过安装预先准备好的样本来研究 Eclipse(可能需要连接因特网)。 多页面编辑器:显示如何...

    c++中嵌入python虚拟机以及扩展例子

    自己写的helloworld程序,从最简单c++中调用python函数,捕捉python出错到c++类封装python类的方法都有。

    generaljs:帮助您处理DOMEvents Webworkers Websockets编码的JS库-解码算法存储FetchAJAX

    log ( "Hello World" ) ; 向JS控制台发出警告 genrl . warn ( "Hello World" ) ; 向JS控制台发送信息 genrl . info ( "Hello World" ) ; JS控制台出错 genrl . error ( "Hello World" ) ; 如何通过ID选择DOM...

    linux大作业报告

    3、编写程序,在/tmp目录下面建立一个test目录,然后在test目录下建立一个空文件hello.txt,注意函数出错处理。 4、编写程序实现一个简单的员工档案管理系统,具备简单的员工资料增加、删除和查询等功能,并采用二...

    《你必须知道的495个C语言问题》

    intf(){char a[]="Hello, world!";} 18 *1.33 下面的初始化有什么问题?编译器提示“invalid initializers ”或其他信息。char *p=malloc(10); 19 1.34 char a[]= "string literal";和char *p="string literal...

Global site tag (gtag.js) - Google Analytics