- 浏览: 407207 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (268)
- java (22)
- Acegi (8)
- Ajax (17)
- Annotation (3)
- Ant (3)
- JBOSS (6)
- Xdoclet (1)
- CSS (20)
- Data Warehouse (11)
- DB2 (3)
- DOM (1)
- dos (2)
- JMF (1)
- JMS (5)
- J2EE (17)
- Hibernate (7)
- struts (10)
- CORBA (1)
- 职业 (2)
- JSF (1)
- JSTL (8)
- 其它 (1)
- Log4j (7)
- svg (7)
- quartz (3)
- web2.0 (2)
- velocity (2)
- apache commons (1)
- js (9)
- html (4)
- sql (3)
- linux (4)
- dwr (14)
- spring (5)
- GWT (7)
- portlet (4)
- 软件工程 (10)
- actionscript (1)
- 测试 (1)
- tomcat (3)
- flash (0)
- 线程 (1)
- mysql (6)
- flex (1)
- oracle (7)
- crystalreport (4)
- itext (4)
- memcache (2)
- linux 监控 (2)
- mongodb (1)
- Kafka (5)
- 网络 (2)
- 分布式计算 (2)
最新评论
-
chenyongxin:
mark
JBoss 4.0.2集群基本知识及配置方法指南 -
softor:
我找到了,下载吧:http://ishare.iask.sin ...
jad是最简单的class反编译为java文件的小工具 (转载) -
softor:
求下载
dodo@lovehang.com
jad是最简单的class反编译为java文件的小工具 (转载) -
juedui0769:
不错!
请问: 如何在 将 log4j.appender ...
Tomcat 日志 配置 (转载) -
spp_1987:
// 建立一个上传文件的输出流
...
Struts上传多个及N个文件的例子
DWR一个外国人实现的很有前途的AJAX框架。
多余的话就不说了,请看DWR的例子程序:
web.xml
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
3
4<web-app id="dwr">
5
6 <display-name>DWR (Direct Web Remoting)</display-name>
7 <description>A demo of how to call Java on the server directly from Javascript on the client</description>
8
9 <servlet>
10 <servlet-name>dwr-invoker</servlet-name>
11 <display-name>DWR Servlet</display-name>
12 <description>Direct Web Remoter Servlet</description>
13 <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
14 <!--
15 <init-param>
16 <param-name>config</param-name>
17 <param-value>WEB-INF/dwr.xml</param-value>
18 </init-param>
19 -->
20 <init-param>
21 <param-name>debug</param-name>
22 <param-value>true</param-value>
23 </init-param>
24 <init-param>
25 <param-name>scriptCompressed</param-name>
26 <param-value>false</param-value>
27 </init-param>
28 <load-on-startup>1</load-on-startup>
29 </servlet>
30
31 <servlet-mapping>
32 <servlet-name>dwr-invoker</servlet-name>
33 <url-pattern>/dwr/*</url-pattern>
34 </servlet-mapping>
35
36</web-app>servlet(uk.ltd.getahead.dwr.DWRServlet)里:
1 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
2 {
3 try
4 {
5 builder.set(req, resp, getServletConfig(), getServletContext(), container);
6 ServletLoggingOutput.setExecutionContext(this);
7
8 processor.handle(req, resp);//该方法对所有request路径/dwr/*有效,在引用JS的时候,使用这个路径执行dwr生成的javascript代码
finally
11 {
12 builder.unset();
13 ServletLoggingOutput.unsetExecutionContext();
14 }
15 }
index.html
1 <?xml version="1.0" encoding="ISO-8859-1" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>DWR - Test Home</title>
6 <script type='text/javascript' src='dwr/interface/Test.js'></script>
7 <script type='text/javascript' src='dwr/engine.js'></script>
8 <script type='text/javascript' src='dwr/util.js'></script>
9 <script>
10 function init() {
11 // This turns off the no-javascript message
12 document.getElementById("start").style.display = "none";
13 // This checks for file: URLs and loading problems
14 if (window.DWREngine == null || window.DWRUtil == null) {
15 document.getElementById("file").style.display = "block";
16 return;
17 }
18 // DWR setup
19 DWREngine.setErrorHandler(function(message) { alert(message); });
20 DWREngine.setWarningHandler(function(message) { alert(message); });
21 DWRUtil.useLoadingMessage();
22 // Turn on the generic error div
23 $("error").style.display = "block";
24 // Load a message from the server
25 Test.getInsert(load);
26 }
27
28 function load(data) {
29 $("error").style.display = "none";
30 DWRUtil.setValue("reply", data);
31 $("reply").style.display = "block";
32 }
33 </script>
34 </head>
35
36 <body onload="init()">
37 .这一部分经过了SERVLET处理:
<script type='text/javascript' src='dwr/interface/Test.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>dwrservlet.doPost方法内processor.handle(req, resp)这个方法如下:
1 public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
2 {
3 String pathInfo = req.getPathInfo();
4 String servletPath = req.getServletPath();
5
6 if (nullPathInfoWorkaround && pathInfo == null)
7 {
8 pathInfo = req.getServletPath();
9 servletPath = HtmlConstants.PATH_ROOT;
10 log.debug("Default servlet suspected. pathInfo=" + pathInfo + "; contextPath=" + req.getContextPath() + "; servletPath=" + servletPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
11 }
12
13 if (pathInfo == null ||
14 pathInfo.length() == 0 ||
15 pathInfo.equals(HtmlConstants.PATH_ROOT))
16 {
17 resp.sendRedirect(req.getContextPath() + servletPath + HtmlConstants.FILE_INDEX);
18 }
19 else if (pathInfo.startsWith(HtmlConstants.FILE_INDEX))
20 {
21 index.handle(req, resp);
22 }
23 else if (pathInfo.startsWith(HtmlConstants.PATH_TEST))
24 {
25 test.handle(req, resp);
26 }
27 else if (pathInfo.startsWith(HtmlConstants.PATH_INTERFACE))
28 {
29 iface.handle(req, resp);//这个方法是我们要关注的
}
。。。。。。。
} iface.handle(req, resp);//这个方法是我们要关注的,来自DefaultInterfaceProcessor
1 public void handle(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
2 {
3 String pathinfo = req.getPathInfo();
4 String servletpath = req.getServletPath();
5 if (pathinfo == null)
6 {
7 pathinfo = req.getServletPath();
8 servletpath = HtmlConstants.PATH_ROOT;
9 }
10 String scriptname = pathinfo;
11 scriptname = LocalUtil.replace(scriptname, HtmlConstants.PATH_INTERFACE, HtmlConstants.BLANK);
12 scriptname = LocalUtil.replace(scriptname, HtmlConstants.EXTENSION_JS, HtmlConstants.BLANK);
13 Creator creator = creatorManager.getCreator(scriptname);
14
15 //resp.setContentType("text/javascript");
16 PrintWriter out = resp.getWriter();
17 out.println();
18
19 out.println("function " + scriptname + "() { }"); //从这里开始DWR自动生成javascript
String path = overridePath;
22 if (path == null)
23 {
24 path = req.getContextPath() + servletpath;
25 }
26 out.println(scriptname + "._path = '" + path + "';"); //$NON-NLS-1$ //$NON-NLS-2$
27
28 Method[] methods = creator.getType().getMethods();
29 for (int i = 0; i < methods.length; i++)
30 {
31 Method method = methods[i];
32 String methodName = method.getName();
33
34 // We don't need to check accessControl.getReasonToNotExecute()
35 // because the checks are made by the doExec method, but we do check
36 // if we can display it
37 String reason = accessControl.getReasonToNotDisplay(req, creator, scriptname, method);
38 if (reason != null && !allowImpossibleTests)
39 {
40 continue;
41 }
42
43 // Is it on the list of banned names
44 if (jsutil.isReservedWord(methodName))
45 {
46 continue;
47 }
48
49 out.print('\n');
50 out.print(scriptname + '.' + methodName + " = function("); //$NON-NLS-1$
51 Class[] paramTypes = method.getParameterTypes();
52 for (int j = 0; j < paramTypes.length; j++)
53 {
54 if (!LocalUtil.isServletClass(paramTypes[j]))
55 {
56 out.print("p" + j + ", "); //$NON-NLS-1$ //$NON-NLS-2$
57 }
58 }
59 out.println("callback) {"); //$NON-NLS-1$
60
61 out.print(" DWREngine._execute(" + scriptname + "._path, '" + scriptname + "', '" + methodName + "\', "); //实现javascript调用java内的方法
for (int j = 0; j < paramTypes.length; j++)
63 {
64 if (LocalUtil.isServletClass(paramTypes[j]))
65 {
66 out.print("false, "); //$NON-NLS-1$
67 }
68 else
69 {
70 out.print("p" + j + ", "); //$NON-NLS-1$ //$NON-NLS-2$
71 }
72 }
73 out.println("callback);"); //$NON-NLS-1$
74
75 out.println('}');
76 }
77
78 out.flush();
79 }DWR例子程序下载地址:http://www.blogjava.net/Files/javajohn/dwr.rar
多余的话就不说了,请看DWR的例子程序:
web.xml
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
3
4<web-app id="dwr">
5
6 <display-name>DWR (Direct Web Remoting)</display-name>
7 <description>A demo of how to call Java on the server directly from Javascript on the client</description>
8
9 <servlet>
10 <servlet-name>dwr-invoker</servlet-name>
11 <display-name>DWR Servlet</display-name>
12 <description>Direct Web Remoter Servlet</description>
13 <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
14 <!--
15 <init-param>
16 <param-name>config</param-name>
17 <param-value>WEB-INF/dwr.xml</param-value>
18 </init-param>
19 -->
20 <init-param>
21 <param-name>debug</param-name>
22 <param-value>true</param-value>
23 </init-param>
24 <init-param>
25 <param-name>scriptCompressed</param-name>
26 <param-value>false</param-value>
27 </init-param>
28 <load-on-startup>1</load-on-startup>
29 </servlet>
30
31 <servlet-mapping>
32 <servlet-name>dwr-invoker</servlet-name>
33 <url-pattern>/dwr/*</url-pattern>
34 </servlet-mapping>
35
36</web-app>servlet(uk.ltd.getahead.dwr.DWRServlet)里:
1 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
2 {
3 try
4 {
5 builder.set(req, resp, getServletConfig(), getServletContext(), container);
6 ServletLoggingOutput.setExecutionContext(this);
7
8 processor.handle(req, resp);//该方法对所有request路径/dwr/*有效,在引用JS的时候,使用这个路径执行dwr生成的javascript代码
finally
11 {
12 builder.unset();
13 ServletLoggingOutput.unsetExecutionContext();
14 }
15 }
index.html
1 <?xml version="1.0" encoding="ISO-8859-1" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>DWR - Test Home</title>
6 <script type='text/javascript' src='dwr/interface/Test.js'></script>
7 <script type='text/javascript' src='dwr/engine.js'></script>
8 <script type='text/javascript' src='dwr/util.js'></script>
9 <script>
10 function init() {
11 // This turns off the no-javascript message
12 document.getElementById("start").style.display = "none";
13 // This checks for file: URLs and loading problems
14 if (window.DWREngine == null || window.DWRUtil == null) {
15 document.getElementById("file").style.display = "block";
16 return;
17 }
18 // DWR setup
19 DWREngine.setErrorHandler(function(message) { alert(message); });
20 DWREngine.setWarningHandler(function(message) { alert(message); });
21 DWRUtil.useLoadingMessage();
22 // Turn on the generic error div
23 $("error").style.display = "block";
24 // Load a message from the server
25 Test.getInsert(load);
26 }
27
28 function load(data) {
29 $("error").style.display = "none";
30 DWRUtil.setValue("reply", data);
31 $("reply").style.display = "block";
32 }
33 </script>
34 </head>
35
36 <body onload="init()">
37 .这一部分经过了SERVLET处理:
<script type='text/javascript' src='dwr/interface/Test.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>dwrservlet.doPost方法内processor.handle(req, resp)这个方法如下:
1 public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
2 {
3 String pathInfo = req.getPathInfo();
4 String servletPath = req.getServletPath();
5
6 if (nullPathInfoWorkaround && pathInfo == null)
7 {
8 pathInfo = req.getServletPath();
9 servletPath = HtmlConstants.PATH_ROOT;
10 log.debug("Default servlet suspected. pathInfo=" + pathInfo + "; contextPath=" + req.getContextPath() + "; servletPath=" + servletPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
11 }
12
13 if (pathInfo == null ||
14 pathInfo.length() == 0 ||
15 pathInfo.equals(HtmlConstants.PATH_ROOT))
16 {
17 resp.sendRedirect(req.getContextPath() + servletPath + HtmlConstants.FILE_INDEX);
18 }
19 else if (pathInfo.startsWith(HtmlConstants.FILE_INDEX))
20 {
21 index.handle(req, resp);
22 }
23 else if (pathInfo.startsWith(HtmlConstants.PATH_TEST))
24 {
25 test.handle(req, resp);
26 }
27 else if (pathInfo.startsWith(HtmlConstants.PATH_INTERFACE))
28 {
29 iface.handle(req, resp);//这个方法是我们要关注的
}
。。。。。。。
} iface.handle(req, resp);//这个方法是我们要关注的,来自DefaultInterfaceProcessor
1 public void handle(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
2 {
3 String pathinfo = req.getPathInfo();
4 String servletpath = req.getServletPath();
5 if (pathinfo == null)
6 {
7 pathinfo = req.getServletPath();
8 servletpath = HtmlConstants.PATH_ROOT;
9 }
10 String scriptname = pathinfo;
11 scriptname = LocalUtil.replace(scriptname, HtmlConstants.PATH_INTERFACE, HtmlConstants.BLANK);
12 scriptname = LocalUtil.replace(scriptname, HtmlConstants.EXTENSION_JS, HtmlConstants.BLANK);
13 Creator creator = creatorManager.getCreator(scriptname);
14
15 //resp.setContentType("text/javascript");
16 PrintWriter out = resp.getWriter();
17 out.println();
18
19 out.println("function " + scriptname + "() { }"); //从这里开始DWR自动生成javascript
String path = overridePath;
22 if (path == null)
23 {
24 path = req.getContextPath() + servletpath;
25 }
26 out.println(scriptname + "._path = '" + path + "';"); //$NON-NLS-1$ //$NON-NLS-2$
27
28 Method[] methods = creator.getType().getMethods();
29 for (int i = 0; i < methods.length; i++)
30 {
31 Method method = methods[i];
32 String methodName = method.getName();
33
34 // We don't need to check accessControl.getReasonToNotExecute()
35 // because the checks are made by the doExec method, but we do check
36 // if we can display it
37 String reason = accessControl.getReasonToNotDisplay(req, creator, scriptname, method);
38 if (reason != null && !allowImpossibleTests)
39 {
40 continue;
41 }
42
43 // Is it on the list of banned names
44 if (jsutil.isReservedWord(methodName))
45 {
46 continue;
47 }
48
49 out.print('\n');
50 out.print(scriptname + '.' + methodName + " = function("); //$NON-NLS-1$
51 Class[] paramTypes = method.getParameterTypes();
52 for (int j = 0; j < paramTypes.length; j++)
53 {
54 if (!LocalUtil.isServletClass(paramTypes[j]))
55 {
56 out.print("p" + j + ", "); //$NON-NLS-1$ //$NON-NLS-2$
57 }
58 }
59 out.println("callback) {"); //$NON-NLS-1$
60
61 out.print(" DWREngine._execute(" + scriptname + "._path, '" + scriptname + "', '" + methodName + "\', "); //实现javascript调用java内的方法
for (int j = 0; j < paramTypes.length; j++)
63 {
64 if (LocalUtil.isServletClass(paramTypes[j]))
65 {
66 out.print("false, "); //$NON-NLS-1$
67 }
68 else
69 {
70 out.print("p" + j + ", "); //$NON-NLS-1$ //$NON-NLS-2$
71 }
72 }
73 out.println("callback);"); //$NON-NLS-1$
74
75 out.println('}');
76 }
77
78 out.flush();
79 }DWR例子程序下载地址:http://www.blogjava.net/Files/javajohn/dwr.rar
发表评论
-
dwr 常见方法
2008-01-16 17:38 998$(); 功能:相当于document.getElement ... -
DWR中提供XML的传递方法
2008-01-16 17:28 841自己用dom4j,所以用dom4j做例子; java ser ... -
DWRUtils API 使用方法(转载)
2008-01-16 17:21 748$("precloneNode1suf") ... -
DWREngine API 使用方法 (转载)
2008-01-16 17:21 2470//简易函数; abc(handler){ } DWRE ... -
dwr简介 (转载)
2008-01-16 16:39 1255最近Ajax比较火,全世界 ... -
dwr学习1 (转载)
2008-01-16 16:35 884这段时间较闲,研究了一 ... -
JAVA中DWR开发项目实战经验(转载)
2008-01-16 16:06 1013自己在公司网站开发总用DWR开发的一个简单聊天 本人也是在网站 ... -
DWR 简化 Ajax 的 portlet 间通信(转载)
2008-01-16 16:04 1227许多开发人员都期待着利用 Ajax 技术来提高基于 Web 的 ... -
关于DWR2.0的配置问题(转载)
2008-01-16 16:00 886自从换工作之后就没有研究过DWR了。下载了最新的DWR2.0M ... -
ajax之旅--dwr探密(转载)
2008-01-16 15:58 787ajax是Asynchronous JavaScript an ... -
DWR使用笔记(转载)
2008-01-16 15:56 681DWR是一个框架,简单的说就是能够在javascript直接调 ... -
把DWR的配置写到Spring的配置文件里(转载)
2008-01-16 15:54 1061要读懂我这篇文章估计需要一些前期知识: 你要知道Spring是 ... -
DWR的学习文档(Hello World,类型转换,Spring,Annotation) (转载)
2008-01-16 15:37 1073DWR是作为远程调用的ajax框架,将服务端的java类,方法 ...
相关推荐
在"dwr"这个压缩包中,很可能是包含了DWR的源码,用于开发者学习、研究或者自定义扩展。导入并运行这些源码,可以让开发者深入理解DWR的工作原理,了解其内部结构和功能实现。 DWR的主要特点包括: 1. **自动类型...
这份"DWR源码(eclipse源码)"是一个学习DWR实现和原理的宝贵资源,特别是对于初学者来说。 **DWR的核心功能:** 1. **异步通信**:DWR通过AJAX(Asynchronous JavaScript and XML)技术实现页面的无刷新更新,提高...
dwr源码
1、 导入dwr.jar包 2、 在web.xml中配置dwr,如下: <!-- 配置DWR --> <servlet-name>dwr-invoker org.directwebremoting.servlet.DwrServlet <init-param> <param-name>debug</param-name> ...
在“java dwr 框架源码”这个主题中,我们可以深入探讨以下几个关键知识点: 1. **DWR的核心概念**:DWR的核心组件包括`Engine`、`Configurator`和`Caucho Hessian`。`Engine`是DWR的核心,负责处理所有请求和响应...
在描述中提到的"自己写的dwr源码实例"意味着这个压缩包中可能有一个由个人开发的、基于DWR的项目,展示了如何使用DWR进行客户端和服务器端的通信。这个实例对于初学者来说是一个很好的学习资源,可以帮助他们理解DWR...
Direct Web Remoting (DWR) 是一个开源Java库,它允许Web应用程序在浏览器和服务器之间进行实时、双向通信,使得JavaScript可以直接调用服务器端的Java方法,极大地增强了Web应用的功能和用户体验。本案例源码提供了...
dwr jar dwr.jar dwr 源码
DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站。它可以允许在浏览器里的代码使用运行在WEB服务器上的JAVA方法,就像它就在...
总的来说,这个压缩包提供了一个全面的学习DWR的资源集合,从理论知识到实践案例,覆盖了DWR的方方面面。通过深入研究这些材料,你不仅可以了解DWR的工作机制,还能学会如何在实际项目中有效地应用它,提升Web应用的...
dwr源码包 dwr 全称direct web remote 将后台java class 映射为前台的一个js 执行js方法 即可通过ajax 操作后台
为dwr的参考必备,通过源码可以了解推送的真正机制。
总的来说,DWR分页源码的分析和学习可以帮助开发者更好地理解和实现Ajax分页,提升Web应用的用户体验。通过深入研究这些代码,我们可以学习到DWR与Ajax的集成、服务器端数据处理以及前端交互设计等方面的知识。
结合DWR的官方文档和这些源码,开发者不仅可以学习到DWR的工作原理,还可以根据需求定制自己的DWR实现,提升Web应用的性能和用户体验。同时,对源码的深入理解也有助于培养开发者的问题排查和调试能力,对于提升个人...
**DWR(Direct Web Remoting)**是一种WEB远程调用框架,主要目的是简化AJAX(Asynchronous JavaScript and XML)开发。通过DWR,开发者可以在客户端的JavaScript中直接调用服务器端的Java方法,并且如同本地调用...
DWR(Direct Web Remoting)是一种Java技术,用于在Web应用程序中实现实时的客户端-服务器通信。它允许JavaScript在浏览器端直接调用服务器端的Java方法,从而减少了页面的刷新,提高了用户体验。本讲解将深入探讨...
通过研究DWR2.0.5的源码,开发者不仅可以深入了解AJAX通信机制,还可以学习到如何设计和实现一个高效的远程调用框架。此外,对于想要提升自己的Java编程技巧,特别是Web开发技能的开发者来说,这是一个宝贵的学习...
DWR学习资料 :DWR 3.0 上传文件.txt DWR3.0反向Ajax示例.txt DWR3.0学习笔记.txt DWR3.0学习网址.txt dwr分页.doc DWR分页代码.doc DWR中文文档.doc DWR中文文档.pdf dwr做comet的完整实现.doc Spring整合DWR comet ...
DWR(Direct Web Remoting)框架是一个开源的Java库,它允许Web应用程序在客户端和服务器之间进行实时的、异步的通信,无需使用XMLHttpRequest或IFrame。DWR的使用大大简化了AJAX(Asynchronous JavaScript and XML...