`
accpxudajian
  • 浏览: 460003 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

配置一个最简洁的DWR

    博客分类:
  • Java
阅读更多

期工作:

1.dwr官网下载dwr.jar(http://directwebremoting.org/dwr/downloads/index.html )

2.将dwr.jar放在自己的lib目录下(同时引入commons-logging.jar,可能适合dwr记录日志有关系,在下边的zip中lib目录中可以找到)。

3.编辑web.xml,加入如下代码:

   <servlet-name>dwr</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</servlet-name>
   <url-pattern>/dwr/*</url-pattern>
 </servlet-mapping>

 4.创建service类 如:

package com;

public class Test {
	public String test(){
		return "hello word";
	}
}
 

5.新建dwr.xml文件,和web.xml放在一起,dwr.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr//dwr30.dtd"> 

<dwr>
	<allow>
		<create creator="new" javascript="Test">
			<param name="class" value="com.Test"/>
		</create>
	</allow>
</dwr>
 

6 测试dwr是否配置成功http://localhost:8080/webapp名称/dwr/index.html

例如我的:http://localhost:8080/emss/dwr/index.html,

如果页面出现

Classes known to DWR:

:字样,恭喜你,dwr配置成功了。

点击Test,进入dwr调试页面,从页面可以看到当前Test的配置信息为(这些信息是需要引入到jsp页面的):

<!-- These paths use .. so that they still work behind a path mapping proxy. The fully qualified version is more cut and paste friendly. -->

Methods For: Test (com.Test)

To use this class in your javascript you will need the following script includes:

  <script type='text/javascript' src='/emss/dwr/interface/Test.js
'></script>
  <script type='text/javascript' src='/emss/dwr/engine.js
'></script>

In addition there is an optional utility script:

  <script type='text/javascript' src='/emss/dwr/util.js
'></script>

 

 

7 jsp页面引用:

 

<%@ page language="java"  pageEncoding="UTF-8"%>
<html>
  <head>
  	<script type='text/javascript' src='/emss/dwr/engine.js'></script>
	<script type='text/javascript' src='/emss/dwr/util.js'></script>
	<script type='text/javascript' src='/emss/dwr/interface/Test.js'></script>
	<script>
		Test.test(function(res){
			alert("test方法返回值:"+res);//返回hello word
		});
	</script>
</html>

 

8 特别注意: 在使用dwr的时候必须引入commons-logging.jar

 

9 结束。

 

 

 

 

 

  • 大小: 44.6 KB
  • 大小: 82.9 KB
  • 大小: 15.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics