在項目中開始使用DWR1.0發現DWR2.0有注解后,采用DWR2.0注解,但是遮增加了web.xml 中DWRServlet中classes參數的信息。終于DWR3.0發布了。采用DWR3.0開發實現完美整合。
DWR 3.0 RC1发布
DWR终于到达3.0版本,刚刚发布了3.0 release candidate 1。DWR(Direct Web Remoting)是一个WEB远程调用框架,能够在javascript直接调用java方法,而不必去写一大堆的javascript代码,利用这个框架可以让AJAX开发变得很简单. 新功能包括:提升RPC性能;提升字节文件上传/下载功能;通过JavaScript实现Java接口;提供可扩展的反向Ajax APIs;TIBCO GI集成;集成Dojo;支持更多的服务器比如Tomcat和Glassfish等等。 详情点击:DWR version 3.0 Release Candidate 1 点击这里下载DWR 3.0 RC1: http://directwebremoting.org/dwr/download |
package com.unutrip.spring.dwr;
/**
*
* @author longgangbai
*
*/
public interface UserService {
public String getUsername(UserVO user);
}
package com.unutrip.spring.dwr;
import org.directwebremoting.annotations.Param;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* @author longgangbai
*
*/
@RemoteProxy(creator = SpringCreator.class, creatorParams = @Param(name = "beanName", value = "userServiceDWR"))
public class UserServiceDWR {
@Autowired
private UserService userService;
@RemoteMethod
public String getUsername(UserVO user) {
return this.userService.getUsername(user);
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
package com.unutrip.spring.dwr;
import org.springframework.stereotype.Service;
/**
*
* @author longgangbai
*
*/
@Service
public class UserServiceImpl implements UserService {
public String getUsername(UserVO user) {
return user.getUsername();
}
}
package com.unutrip.spring.dwr;
import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.RemoteProperty;
/**
*
* @author longgangbai
*
*/
@DataTransferObject
public class UserVO {
@RemoteProperty
private String username;
@RemoteProperty
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
在applicationContext中配置如下:
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" default-autowire="byName">
<context:annotation-config/>
<context:component-scan base-package="com.unutrip.spring.dwr" />
<!-- order值越小, 优先级越高 -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="1" />
</bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
在action-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd" default-autowire="byName">
<!--
<tx:annotation-driven/>
-->
<!-- DWR -->
<!-- New DWR capabilities-->
<dwr:configuration>
<dwr:convert class="com.unutrip.spring.dwr.UserVO" type="bean" />
<dwr:signatures>
<![CDATA[
]]>
</dwr:signatures>
</dwr:configuration>
<dwr:annotation-config />
<dwr:url-mapping />
<!-- 部署项目时, 请把debug设为false -->
<dwr:controller id="dwrController" debug="true" />
</beans>
註意點:添加了顔色哦!!哈哈哈
兩個查看開源源代碼的網站:
http://fisheye5.cenqua.com/browse/dwr/java/org/directwebremoting/dwrp/Batch.java?r=1.16#l109
相关推荐
在本文中,我们将探讨如何将Direct Web Remoting (DWR) 3.0与...通过这种方式,DWR 3.0与Spring 2.5的整合使用注解配置简化了开发流程,使得Java后端的方法可以直接在客户端JavaScript中调用,实现前后端的无缝交互。
标题中的“Spring2.5+DWR3.0整合实现autocomplete”是指在Web开发中,使用Spring 2.5框架与Direct Web Remoting (DWR) 3.0库结合,来实现一个自动补全(autocomplete)功能。这个功能常见于搜索引擎、表单输入等场景...
ssm整合开发,小程序毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统...
我们涉及到了一套完整的开发环境与一系列关键技术组件,这包括了Eclipse3.4作为集成开发环境、Tomcat-5.5.28作为应用服务器、Mysql-5.1.49作为数据库系统,以及一个由Struts2.0、Spring2.5和Hibernate3.2构成的流行...
8.1 用Spring MVC开发简单的Web应用 280 8.1.1 问题 280 8.1.2 解决方案 281 8.1.3 工作原理 283 8.2 用@RequestMapping映射请求 293 8.2.1 问题 293 8.2.2 解决方案 294 8.2.3 工作原理 294 8.3 ...
8.1 用Spring MVC开发简单的Web应用 280 8.1.1 问题 280 8.1.2 解决方案 281 8.1.3 工作原理 283 8.2 用@RequestMapping映射请求 293 8.2.1 问题 293 8.2.2 解决方案 294 8.2.3 工作原理 294 8.3 ...