- 浏览: 1505062 次
- 性别:
- 来自: 厦门
文章分类
- 全部博客 (516)
- Java (49)
- Java/Struts 2.0 (25)
- Java/Spring、Spring MVC (11)
- Java/Quartz (3)
- Java/Lucene (6)
- Java/Hibernate (19)
- Java/openJPA (7)
- Java/DWR (7)
- Java/Security、Spring Security/OAuth2 (6)
- Java/Threading (9)
- Java/XML (22)
- java/design pattern (4)
- Android (2)
- JavaScript (46)
- jquery (3)
- DB/MySQL (23)
- DB/Oracle (16)
- PHP (25)
- CSS (20)
- Linux (38)
- C/C++、DLL、Makefile、VC++ (31)
- 正则 (9)
- Eclipse (4)
- 安全、网络等概念 (25)
- 集群 (7)
- 网页 (5)
- 视频\音频 (1)
- HTML (6)
- 计算机数学/算法 (3)
- Virtualbox (1)
- LDAP (2)
- 数据挖掘 (6)
- 工具破解 (1)
- 其他 (13)
- Mail (1)
- 药材 (3)
- 游戏 (2)
- hadoop (13)
- 压力测试 (3)
- 设计模式 (3)
- java/Swing (2)
- 缓存/Memcache (0)
- 缓存/Redis (1)
- OSGI (2)
- OSGI/Gemini (0)
- 文档写作 (0)
- java/Servlet (3)
- MQ/RabbitMQ (2)
- MQ/RocketMQ (0)
- MQ/Kafka (1)
- maven (0)
- SYS/linux (1)
- cache/redis (1)
- DB/Mongodb (2)
- nginx (1)
- postman (1)
- 操作系统/ubuntu (1)
- golang (1)
- dubbo (1)
- 技术管理岗位 (0)
- mybatis-plus (0)
最新评论
-
pgx89112:
大神,请赐我一份这个示例的项目代码吧,万分感谢,1530259 ...
spring的rabbitmq配置 -
string2020:
不使用增强器 怎么弄?
OpenJPA的增强器 -
孟江波:
学习了,楼主,能否提供一份源代码啊,学习一下,十分感谢!!!4 ...
spring的rabbitmq配置 -
eachgray:
...
spring-data-redis配置事务 -
qljoeli:
学习了,楼主,能否提供一份源代码啊,学习一下,十分感谢!!!1 ...
spring的rabbitmq配置
<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
第一个 HelloWorld 程序!
<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
首先需要配置“ DWR 环境”,那样才能使用 javascript 调用 java 类的代码
<!-- [if !supportLists]-->1、 <!-- [endif]-->添加 dwr.jar 到 [web-app]/WEB-INF/lib 目录中。
<!-- [if !supportLists]-->2、 <!-- [endif]-->在 [web-app]/WEB-INF 目录下创建 dwr.xml 文件,并写入以下代码:
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd" >
< dwr >
< allow >
</ allow >
</ dwr >
<!-- [if !supportLists]-->3、 <!-- [endif]-->修改 web.xml 文件,内容如下
< servlet >
< servlet-name > dwr-invoker </ servlet-name >
< servlet-class >
org.directwebremoting.servlet.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 >
如果使用 logging 时, commons-logging 和 log4j 是默认的配置,当然也可以使用 HttpServlet.log() 方法。
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
有效值为: FATAL, ERROR, WARN (the default), INFO and DEBUG.
这样就把 DWR 环境配置好了!那么开始第一个 HelloWorld 程序
第一步:编写 HelloWorld.java :
package com.willmobile.ajaxtm;
public class HelloWorld {
public String sayHelloWorldTo(String name) {
return "Hello World " + name + "!";
}
}
第二步:编辑 dwr.xml 文件,在 <allow> 标签内添加下面代码:
<create creator="new" javascript="Helloworld" scope="page">
<param name="class" value="com.willmobile.ajaxtm.HelloWorld" />
</create>
为了与java 的HelloWorld 类表示区别javascript 的Helloworld 的“w ”是小写的
第三步:把web 应用发布到tomcat 的webapps 里面, 运行tomcat 服务器, 然后输入以下
http://localhost:8080/web-app
/dwr/
<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
把上面的三个<script> 都拷贝起来,并且在web-app 下面创建一个index.jsp 的页面。其代码如下:
<? xml version = "1.0" encoding = "UTF-8" ?>
< html >
< head >
< script type = 'text/javascript' src = '/learnAjax/dwr/interface/Helloworld.js' ></ script >
< script type = 'text/javascript' src = '/learnAjax/dwr/engine.js' ></ script >
< script type = 'text/javascript' src = '/learnAjax/dwr/util.js' ></ script >
< script type = "text/javascript" >
window.onload = function () {
Helloworld.sayHelloWorldTo( "JavaTwo 2008" , function (returnStr) {
$( 'output' ).innerHTML = returnStr;
} );
}
</ script >
</ head >
< body >
< h2 id = "output" ></ h2 >
</ body >
</ html >
第四步:输入 http://localhost:8080/web-app 即可看到想要的结果了!
<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if !mso]> <span class="mceItemObject" classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui> </span> <style> st1\:*{behavior:url(#ieooui) } </style> <![endif]--> <!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]-->
创建一个<creator> 与<converter> 结合的例子:
第一步:创建一个Person bean :
package com.my.learn.beanConvertor;
public class Person {
private String name ;
private int age ;
public int getAge() {
return age ;
}
public void setAge( int age) {
this . age = age;
}
public String getName() {
return name ;
}
public void setName(String name) {
this . name = name;
}
}
第二步:创建一个Remote bean ,这个做为远程调用的
package com.my.learn.beanConvertor;
public class Remoted {
private Person p ;
public void setPerson(Person p) {
this . p = p;
System. out .println( "The person's name is: " + p.getName()
+ " and age is: " + p.getAge()); // 查看运行效果
}
}
第三步:在<allow> 标签里注册bean :
< create javascript = "remoted" creator = "new" >
< param name = "class" value = "com.my.learn.beanConvertor.Remoted" />
</ create >
< convert match = "com.my.learn.beanConvertor.Person" converter = "bean" />// 这个转换是为Remoted.setPerson(Person) 转换类型用的。也就是指从javascript 传参数到java 时需要转换
如果使converter = "object" 的话,那么还得需要一个参数,才能与converter = "bean" 达到相的效果。如下:
< convert match = "com.my.learn.beanConvertor.Person" converter = "object" >
< param name = "force" value = "true" />
</ convert >
第四步:
输入http://localhost:8080/learndwr/dwr 复制三个<script> 所以定的脚本文件, 并且粘贴到新建的html 网页里头
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head >
< script type = 'text/javascript' src = '/learndwr/dwr/interface/remoted.js' ></ script >
< script type = 'text/javascript' src = '/learndwr/dwr/engine.js' ></ script >
< script type = 'text/javascript' src = '/learndwr/dwr/util.js' ></ script >
< script type = "text/javascript" >
var p = { name: "Fred" ,age:21 } ;
<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:UseFELayout/> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]-->
- DWR学习笔记.rar (93.4 KB)
- 下载次数: 10
发表评论
-
面向 Java 开发人员的 Ajax: 使用 Jetty 和 Direct Web Remoting 编写可扩展的 Comet 应用程序
2009-11-23 18:06 1056使用 Continuations 和 Revers ... -
DWR 3.0 上传文件
2009-11-22 20:54 7139第一步:需要文件包,其实就是dwr 3.0中例子所需要的包, ... -
利用dwr跨域上传文件的实现
2009-11-22 19:18 2034最近产品中需要在一个域下,上传文件到另外一个域,并且显示上传文 ... -
DWR Reverse Ajax 显示服务器的时间
2009-11-21 20:34 2126第一步:最基本也是最重要的,要记得配置web.xml中与rev ... -
DWR调用session
2009-04-29 11:03 1250public Boolean memberExsit(Http ... -
DWR 执行前/后消息 setPreHook/setPostHook
2008-09-05 16:30 1755function checkShopTitle(){ var ...
相关推荐
很好的DWR2.0中文文档 深入浅出,通俗易懂, 学习dwr必备良书
DWR3.0.jar、DWR的实例war和DWR2.0中文说明文档
鄙视网上那些抄来抄去的,又不能用的垃圾 dwr2.0最简单例子实用亲测试
NULL 博文链接:https://liuzidong.iteye.com/blog/346042
作为一个java open source library,DWR可以帮助开发人员完成应用AJAX技术的web程序。它可以让浏览器上的javascript方法调用运行在web服务器上java方法。
dwr2.0中文文档.pdf dwr2.0中文文档.pdf dwr2.0中文文档.pdf
NULL 博文链接:https://yxwang0615.iteye.com/blog/979630
dwr2.0 spring 3.0 整合示例
DWR2.0 相关配置文件 DWR2.jar + DWR.xml + DWR2.0.dtd + Web.xml
Dwr2.0中文手册,详细的DWR API
dwr的入门实例,dwr2.0和3.0 jar包都有,可分别测试效果。用myeclipse important 项目,开启tomcat即可运行。
dwr 2.0 的 dtd 和官方网站首页 新鲜的,还热乎呢,回去好好用吧
dwr2.0后台推送demo,包含第三方登陆,响应成功(是根据sessionID)做的判断。 内含dwr2.0.jar,js都在包里的不用另外找的
资源名称:DWR 2.0中文文档 V0.9内容简介: Ajax向我们袭来的时候,很多写代码的程序员看到了Ajax的发展前景,但并不是每一个程序员都能将页面与代码完美整合在一起,DOM、CSS、javascript让人眼花缭乱,不知...
使用dwr2.0实现服务器推客户端(结合响应socket服务器推消息)