dwr的基本使用,异常处理,和spring集成方法(二)

2014-11-24 10:14:23 · 作者: · 浏览: 1
xcption!");
alert(exception.message);
}
function exceptionHandler(exceptionString, exception){
//alert("lai excption2222!");
alert(exception.message);
}






Name:




Reply:



和spring集成方法:
编写远程访问类


package com.dwr3.annotation;

import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;

@RemoteProxy(creator=SpringCreator.class)
public class SayHello {
@RemoteMethod()
public String sayHello(){
return "say hello";
}
@RemoteMethod
public String sayHello(String name){
return name+" say hello";
}
}

2.配置Web.xml文件


< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


org.springframework.web.context.ContextLoaderListener


contextConfigLocation
classpath:applicationContext.xml


dwr
org.directwebremoting.spring.DwrSpringServlet

debug
true


crossDomainSessionSecurity
false


allowScriptTagRemoting
true



dwr
/dwr/*


index.jsp

3.配置Spring配置文件(applicationContext.xml)


< xml version="1.0" encoding="UTF-8" >
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-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">









4.编写测试代码


<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>




Insert title here
<script type='text/java script' src='/MyBatis/dwr/interface/sayHello.js'>
<script type='text/java script' src='/MyBatis/dwr/engine.js'>

<script type="text/java script">
function SayHelloTest(){
var str = document.getElementById("name").value;
sayHello.sayHello(str,function(value){
alert(value);
});
}