- 浏览: 252904 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
July01:
推荐用StratoIO打印控件,浏览器和系统的兼容性都很好,而 ...
B/S结构下套打票据实现 - Lodop打印组件 -
iTarget:
原原文::http://blog.csdn.net/steve ...
加减乘除的问题 - BigDecimal -
iTarget:
原文:http://blog.csdn.net/gqm1982 ...
加减乘除的问题 - BigDecimal -
iTarget:
在Java中,要想实现精确计算,解决方案是使用BigDecim ...
加减乘除的问题 - BigDecimal -
叶寒_:
...
JSP简单标签
2007-1-20 周三
配置DWR:
1、Web.xml中添加如下内容:
xml 代码
- < servlet >
- < servlet-name > dwr-invoker servlet-name >
- < display-name > DWR Servlet display-name >
- < description > Direct Web Remoter Servlet description >
- < servlet-class > uk.ltd.getahead.dwr.DWRServlet servlet-class >
- < init-param >
- < param-name > debug param-name >
- < param-value > true param-value >
- init-param >
- servlet >
- < servlet-mapping >
- < servlet-name > dwr-invoker servlet-name >
- < url-pattern > /dwr/* url-pattern >
- servlet-mapping >
2、在web下新建dwr.xml配置文件
入门级的DWR例子
java 代码
- public class Apartment {
- private int id;
- private int bedrooms;
- private int bathrooms;
- private int price;
- private String address;
- private String city;
- private String province;
- public int getId() {
- return id;
- }
- public void setId( int id) {
- this .id = id;
- }
- public String getAddress() {
- return address;
- }
- public void setAddress(String address) {
- this .address = address;
- }
- public int getBathrooms() {
- return bathrooms;
- }
- public void setBathrooms( int bathrooms) {
- this .bathrooms = bathrooms;
- }
- public int getBedrooms() {
- return bedrooms;
- }
- public void setBedrooms( int bedrooms) {
- this .bedrooms = bedrooms;
- }
- public String getCity() {
- return city;
- }
- public void setCity(String city) {
- this .city = city;
- }
- public int getPrice() {
- return price;
- }
- public void setPrice( int price) {
- this .price = price;
- }
- public String getProvince() {
- return province;
- }
- public void setProvince(String province) {
- this .province = province;
- }
- }
java 代码
- package ajax.dwr.simpledwr;
- import java.util.ArrayList;
- import java.util.List;
- public class ApartmentDAO {
- public List findApartments( int bedrooms, int bathrooms, int price) {
- List list = findList(bedrooms, bathrooms, price);
- return list;
- }
- public int countApartments( int bedrooms, int bathrooms, int price) {
- return findList(bedrooms, bathrooms, price).size();
- }
- private List findList( int bedrooms, int bathrooms, int price) {
- List list = initData();
- for ( int i = 0 ; i < list.size(); i++) {
- Apartment apartment = (Apartment) list.get(i);
- if (apartment.getBedrooms() < bedrooms
- && apartment.getBathrooms() < bathrooms
- && apartment.getPrice() >= price) {
- list.remove(i);
- }
- }
- return list;
- }
- private List initData() {
- List list = new ArrayList();
- Apartment apartment = new Apartment();
- apartment.setId( 16001 );
- apartment.setBedrooms( 1 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 850 );
- apartment.setAddress( "123 King St. East" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16002 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1000 );
- apartment.setAddress( "1023 Yonge Ave" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16003 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1050 );
- apartment.setAddress( "27 Winchester St" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16004 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1350 );
- apartment.setAddress( "774 Yonge Ave" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16005 );
- apartment.setBedrooms( 4 );
- apartment.setBathrooms( 3 );
- apartment.setPrice( 1550 );
- apartment.setAddress( "1054 Rouge Valley Dr." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16006 );
- apartment.setBedrooms( 5 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1850 );
- apartment.setAddress( "207 Queens Quay West" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16007 );
- apartment.setBedrooms( 3 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1850 );
- apartment.setAddress( "10 Yorkville Ave." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16008 );
- apartment.setBedrooms( 4 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1400 );
- apartment.setAddress( "3 Watline Dr" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16009 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1180 );
- apartment.setAddress( "98 St. Joseph St." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16010 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1050 );
- apartment.setAddress( "93 Lombard St." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16011 );
- apartment.setBedrooms( 3 );
- apartment.setBathrooms( 3 );
- apartment.setPrice( 1150 );
- apartment.setAddress( "7201 St. Clair Ave. West" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16012 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 950 );
- apartment.setAddress( "12 Eglington Ave. E." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16013 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1100 );
- apartment.setAddress( "352 Dufferin St" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16014 );
- apartment.setBedrooms( 2 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1350 );
- apartment.setAddress( "2224 Wellington St. W" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16015 );
- apartment.setBedrooms( 4 );
- apartment.setBathrooms( 3 );
- apartment.setPrice( 1550 );
- apartment.setAddress( "1454 College St." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16016 );
- apartment.setBedrooms( 5 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1850 );
- apartment.setAddress( "256 Peter St." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16017 );
- apartment.setBedrooms( 3 );
- apartment.setBathrooms( 1 );
- apartment.setPrice( 1850 );
- apartment.setAddress( "6 The Esplanade" );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- apartment.setId( 16018 );
- apartment.setBedrooms( 4 );
- apartment.setBathrooms( 2 );
- apartment.setPrice( 1400 );
- apartment.setAddress( "9 Mercer St." );
- apartment.setCity( "Toronto" );
- apartment.setProvince( "ON" );
- list.add(apartment);
- return list;
- }
- }
dwr.xml文件的配置
xml 代码
- < dwr >
- < allow >
- < convert converter = "bean" match = "ajax.dwr.simpledwr.Apartment" /> //定义bean
- < create creator = "new" javascript = "ApartmentDAO" class = "ajax.dwr.simpledwr.ApartmentDAO" >
- < include method = "findApartments" />
- < include method = "countApartments" />
- create >
- allow >
- dwr >
js 代码
- "text/css"
media=
"screen"
>
- @
import
url( style.css );
-
-
- <script src=' dwr="" <="" span="">interface
/ApartmentDAO.js'></script>
- <script src=' dwr="" engine.js'=""></script>
- <script src=' dwr="" util.js'=""></script>
- <script>
-
//统计总数
-
function
updateTotal() {
- $(
"resultTable"
).style.display = 'none';
-
var
bedrooms = document.getElementById(
"bedrooms"
).value;
-
var
bathrooms = document.getElementById(
"bathrooms"
).value;
-
var
price = document.getElementById(
"price"
).value;
- ApartmentDAO.countApartments(loadTotal, bedrooms, bathrooms, price);
-
//DWR使用得巧妙之处 ,调用ApartmentDAO的countApartments方法在传入bedrooms, bathrooms, price三个参数的同时
-
//将其返回的结果 赋值给loadTotal(data)方法
- }
-
-
function
updateResults() {
- DWRUtil.removeAllRows(
"apartmentsbody"
);
//删除apartmentsbody的所有子child
-
var
bedrooms = document.getElementById(
"bedrooms"
).value;
-
var
bathrooms = document.getElementById(
"bathrooms"
).value;
-
var
price = document.getElementById(
"price"
).value;
- ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);
- $(
"resultTable"
).style.display =
''
;
- }
-
-
var
getId =
function
(unit) {
return
unit.id };
-
var
getAddress =
function
(unit) {
return
unit.address };
-
var
getBedrooms =
function
(unit) {
return
unit.bedrooms };
-
var
getBathrooms =
function
(unit) {
return
unit.bathrooms };
-
var
getPrice =
function
(unit) {
return
unit.price };
-
-
function
loadTotal(data) {
- document.getElementById(
"totalRecords"
).innerHTML = data;
- }
-
-
function
fillTable(apartment) {
- DWRUtil.addRows(
"apartmentsbody"
, apartment, [ getId, getAddress, getBedrooms, getBathrooms, getPrice ]);
- }
-
- </script>
- "text/css" media= "screen" >
- @ import url( style.css );
- <script src=' dwr="" <="" span="">interface /ApartmentDAO.js'></script>
- <script src=' dwr="" engine.js'=""></script>
- <script src=' dwr="" util.js'=""></script>
- <script>
- //统计总数
- function updateTotal() {
- $( "resultTable" ).style.display = 'none';
- var bedrooms = document.getElementById( "bedrooms" ).value;
- var bathrooms = document.getElementById( "bathrooms" ).value;
- var price = document.getElementById( "price" ).value;
- ApartmentDAO.countApartments(loadTotal, bedrooms, bathrooms, price);
- //DWR使用得巧妙之处 ,调用ApartmentDAO的countApartments方法在传入bedrooms, bathrooms, price三个参数的同时
- //将其返回的结果 赋值给loadTotal(data)方法
- }
- function updateResults() {
- DWRUtil.removeAllRows( "apartmentsbody" ); //删除apartmentsbody的所有子child
- var bedrooms = document.getElementById( "bedrooms" ).value;
- var bathrooms = document.getElementById( "bathrooms" ).value;
- var price = document.getElementById( "price" ).value;
- ApartmentDAO.findApartments(fillTable, bedrooms, bathrooms, price);
- $( "resultTable" ).style.display = '' ;
- }
- var getId = function (unit) { return unit.id };
- var getAddress = function (unit) { return unit.address };
- var getBedrooms = function (unit) { return unit.bedrooms };
- var getBathrooms = function (unit) { return unit.bathrooms };
- var getPrice = function (unit) { return unit.price };
- function loadTotal(data) {
- document.getElementById( "totalRecords" ).innerHTML = data;
- }
- function fillTable(apartment) {
- DWRUtil.addRows( "apartmentsbody" , apartment, [ getId, getAddress, getBedrooms, getBathrooms, getPrice ]);
- }
- </script>
发表评论
-
JavaScript事件
2010-06-17 16:32 1297Javascript的事件绑定主要有四种方法: 1、在DOM ... -
TextRange对象
2010-06-06 15:14 3141因用户要求方与TextRange对象结缘,用于处理JavaSc ... -
jQuery Alert、Prompt、Confirm对话框
2010-06-01 22:49 6275最近项目中频繁与jQuery打交道,仔细研究了一下这些插件的实 ... -
Jquery支持键盘功能的计算器
2010-06-01 22:34 3039最近用户提出需要一个Web版本的计算器,在网路上寻找了半天,有 ... -
屏蔽IE浏览器中的功能键
2010-06-01 22:29 1570<script> document.onh ... -
模式对话框
2010-05-08 16:10 888父窗口: function ope ... -
JavaScript的数组创建
2010-05-07 23:15 900var a = new Array( ); a[0] ... -
JavaScript的trim函数
2010-05-07 22:49 1051//去掉左右空格 String.prototype. ... -
Closure闭包
2010-05-07 08:06 1121所谓“闭包”,指的是一个拥有许多变量和绑定了这些变量的环境的表 ... -
向回调函数传递更多信息
2009-03-22 11:22 1696回调函数只能接受一 ... -
Javabean作为对象传入JS
2009-03-22 11:19 1680<convert converter="bea ... -
采用callback调用
2009-03-22 11:17 964<create creator="new&qu ... -
Java集合同JS数组转换
2009-03-22 11:15 2983<create creator="new&qu ... -
Javabean在dwr中使用
2009-03-22 11:14 903<convert converter="bea ... -
AJAX基础教程-9 AutoComplete
2007-02-14 09:53 1754java 代码 package ajax.fou ... -
AJAX基础教程-8 Tool Tips
2007-02-14 09:50 1326java 代码 package ajax.fou ... -
AJAX基础教程-7 AutoRefresh Page
2007-02-13 10:59 1512js 代码 <script type=& ... -
AJAX基础教程-6 Dynamic List
2007-02-13 10:55 1419js 代码 <script type=&l ... -
AJAX基础教程-5 Ajax Validate
2007-02-13 10:49 1372java 代码 package ajax.fou ... -
AJAX基础教程-4 GetAndPostExample
2007-02-10 17:27 1454java 代码 package ajax.fou ...
相关推荐
总结来说,利用Ajax和DWR框架实现的二级联动下拉列表,使得用户可以在不刷新页面的情况下完成多级选择,提升了用户体验。同时,DWR的使用简化了前后端交互的复杂性,使得开发更为高效。通过阅读和理解提供的源代码,...
总之,Ajax DWR框架是实现高效、互动的Web应用的重要工具,它简化了前后端交互的过程,提高了开发效率,并且提供了丰富的功能和良好的安全性。在"JavaDwr"压缩包中,你可以探索和学习如何利用DWR来构建动态Web应用。
DWR(Direct Web Remoting)是一个开源Java框架,它简化了AJAX在Java应用程序中的应用。DWR使得JavaScript和Java之间可以直接通信,就像它们是同一语言一样,消除了传统AJAX需要通过XML或JSON进行数据交换的复杂性。...
在提供的“AJAX框架DWR简单应用.pdf”文件中,你可能会找到关于如何设置DWR环境、编写Java接口、配置DWR配置文件、在前端JavaScript中使用DWR,以及示例代码和实际运行效果的详细教程。这个文件是学习和理解DWR工作...
**Ajax和DWR框架详解** Ajax(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使得网页实现异步更新。这种方式可以让...
在本文中,我们将深入探讨如何使用Ajax、Direct Web Remoting (DWR) 框架以及Hibernate ORM工具来实现一个自动补全功能。这个功能类似于百度搜索引擎中的输入提示,能够根据用户输入的字符动态地提供可能的搜索建议...
总的来说,Ajax和DWR框架的结合使用,可以显著提升Web应用的用户体验,减少不必要的页面刷新,提高数据处理效率。同时,通过DWR与主流Java框架的集成,开发者可以更方便地在大型项目中引入Ajax技术,而不必重构大量...
在这个"ajax的DWR框架入门例子"中,我们将深入理解DWR如何工作以及如何在实际项目中应用。这个例子包含了源代码和调试成功的案例,这意味着我们可以直接运行和学习,而无需从零开始搭建环境。 首先,DWR的基本概念...
**AJAX_DWR框架详解** AJAX (Asynchronous JavaScript and XML) 和 DWR (Direct Web Remoting) 是两种在Web开发中广泛使用的技术,它们共同构成了一个强大的框架,用于构建高度交互性和动态的Web应用程序。AJAX允许...
**AJAX技术之DWR框架入门** AJAX(Asynchronous JavaScript and XML)是一种在无需刷新整个页面的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使得网页实现异步更新。这种技术可以提升...
Java+dwr框架实现聊天室是使用Java语言和dwr框架实现的服务器推技术,实现了实时通信的聊天室功能。下面将详细介绍该技术的实现过程和相关知识点。 一、dwr 框架简介 dwr(Direct Web Remoting)是一种基于Ajax...
学习和理解Ajax及DWR框架,可以帮助开发者构建更加高效、互动性强的Web应用,提升用户在浏览网页时的体验。无论是前端的JavaScript编程,还是后端的Java服务,DWR都提供了强大的工具来简化这个过程。对于希望深入...
本篇文章将深入探讨如何在MyEclipse环境下,结合Struts与Ajax的DWR框架,实现高效的前后端通信。 ### 1. Struts与Ajax的集成 **Struts** 是一个基于MVC设计模式的Java Web框架,它将业务逻辑、视图和控制逻辑分离...
**DWR(Direct Web Remoting)框架学习指南** ...通过学习和实践DWR框架,开发者可以创建更加动态、响应式的Web应用,提升用户的交互体验。理解DWR的工作原理以及如何配置和使用,对于开发人员来说是非常有价值的技能。
本文通过一个具体的示例——无限级树型菜单的实现,展示了如何使用DWR框架简化AJAX应用的开发过程。该示例主要涉及以下几个步骤: 1. **服务器端Java类设计**:首先需要定义服务器端的Java类,这些类包含了将被...
**Java AJAX 框架 DWR 全面解析** DWR (Direct Web Remoting) 是一个强大的Java AJAX框架,它允许在浏览器和服务器之间进行直接的JavaScript与Java对象的交互,使得开发者能够轻松构建富客户端应用程序。DWR的出现...
1. **DWR框架基础** DWR的核心概念是反向Ajax,它创建了一种机制,使得JavaScript可以直接调用服务器端的Java方法,就像它们是本地函数一样。这样,开发者可以轻松地将服务器端的功能暴露给前端,而无需手动处理...
例如,在压缩包内的文件"A051]使用DWR开发AJAX+For+J2EE.wrf"可能是一个演示或者教程,详细介绍了如何使用DWR框架在J2EE环境中构建AJAX应用。这个文件可能涵盖从安装DWR,配置web.xml,编写可远程调用的Java类,到在...
总的来说,DWR框架通过提供便捷的工具和库,使开发者能够更轻松地构建动态、交互性强的Web应用,利用Ajax技术提升用户体验,而这个"**dwr包**"就是实现这一目标的基础。在实际项目中,正确理解和使用这些jar文件及...