and analysis of the use of DWR

1. Download dwr.jar, to add it to WEB-INF/lib directory
2. Modify web.xml file, add the mapping DWRServlet

<servlet-name> dwr-invoker </ servlet-name>
<servlet-class> org.directwebremoting.servlet.DwrServlet </ servlet-class>
<param-name> debug </ param-name>
<param-value> true </ param-value>
</ init-param>
</ servlet>

<servlet-name> dwr-invoker </ servlet-name>
<url-pattern> / dwr / * </ url-pattern>
</ servlet-mapping>

3. Configure dwr, in WEB-INF directory, add dwr.xml documents for DWR to know when to run what should be given JavaBean to generate the corresponding javascript library!

<? xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE dwr PUBLIC "- / / GetAhead Limited / / DTD Direct Web Remoting 2.0 / / EN" "">
<create creator="new" javascript="test1">
<param name="class" value="com.bjsxt.dwr.Test1"/>
</ create>
</ allow>
</ dwr>
The meaning of this configuration is to create a javascript object Test1 database, and the library name is test1, simultaneously, that is what we call in the JSP page, when this object by the use of the name, see the following code and JavaBean JSP example:

4, the following are Test1 the JavaBean source code: package com.bjsxt.dwr;

public class Test1 (

public String sayHello (String name) (
return "Hello," + name;


5, in the JSP use!

<% @ Page language = "java" contentType = "text / html; charset = GB18030"
pageEncoding = "GB18030"%>
<! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN">
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<script type="text/javascript" src="dwr/engine.js"> </ script>
<script type="text/javascript" src="dwr/util.js"> </ script>
<script type="text/javascript" src="dwr/interface/test1.js"> </ script>
<title> Insert title here </ title>
<script type="text/javascript">
function sayHello () (
test1.sayHello ( "Si-ddd",
function (data) (
alert (data);
</ script>
</ head>
<a href="#"> Test1 </ a>
</ body>
</ html>

DWR Principle
Through the study in front of five chapters, an overall understanding of the DWR, but I am still not very clear details of the core. Finally my solution is a single-step debugging, debugging will be followed by a string of all things string, DWR principle on the clear, clear core production line, the other is supporting, no need to re-analyzed. Ah clever foreigners taking.
We DWR as an example of the first sample Dynamically Text
1, in which we embed index.html
<script type='text/javascript' src='../dwr/engine.js'> </ script>
<script type='text/javascript' src='../dwr/util.js'> </ script>
<script type='text/javascript' src='../dwr/interface/Demo.js'> </ script>
DWR front of the two systems are required to load the default, Demo.js are corresponding to According to theory, as long as the web.xml and dwr.xml configured, then we will be able to operate on the client Demo.js, similar to the operation of server-side
HTML source:
<input type="text"/>
<input value="Send" type="button"/>
Reply: <span> </ span>
</ p>

Javascript source:
function update () (
var name = dwr.util.getValue ( "demoName");
Demo.sayHello (name, function (data) (
dwr.util.setValue ( "demoReply", data);

Java source:
package org.getahead.dwrdemo.simpletext;
public class Demo (
public String sayHello (String name) (
return "Hello," + name;

<? xml version = "1.0" encoding = "UTF-8"?>
"- / / GetAhead Limited / / DTD Direct Web Remoting 2.0 / / EN"
<create creator="new" javascript="Demo">
<param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/>
</ create>
</ allow>
</ dwr>

分类:AJAX 时间:2009-03-06 人气:548
blog comments powered by Disqus


  • Java parsing XML documents (2): sax read xml file export excel 2010-03-22

    1. Concept SAX (Simple API for XML), event-based XML Simple API, parsing XML documents is one of the two API. 2. Sax parsing 1. Use to the package: javax.xml.parsers: parser factory tools org.xml.sax: provides the core SAX API For example: import jav

  • DOM4J on XML documents to read and write operations such as additions and deletions to change 2010-03-16

    XML documents with DOM4J on CRUD operations such as reading and writing is my own exercises, and notes there is no order and only later see use. Main method in the constructor to do the simple instructions, involved XML, XSD, DTD document is no longe

  • Java parsing XML documents four methods 2010-05-07

    1) DOM (JAXP Crimson parser) DOM is platform-and language-independent manner, said the official W3C standard XML document. DOM is a hierarchical organization of nodes or pieces of information collection. This hierarchy allows the developer to find sp

  • Android to create XML documents 2010-08-10

    Now, we just look at a concrete example to illustrate how to use the XmlSerializer. private String writeXml () ( XmlSerializer serializer = Xml.newSerializer (); StringWriter writer = new StringWriter (); try ( serializer.setOutput (writer); / / <? X

  • Using dom4j to create, edit XML documents and format the output and the Chinese to solve the problem 2010-08-22

    package com.holen.dom4j; import; import; import java.util.Iterator; import java.util.List; import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import

  • Java programming language commonly used in the method of updating XML documents 2010-09-28

    Quoted from This paper briefly discusses the Java programming language update XML documents in the four commonly used methods, and analysis of the merits of the four methods. Secondly, the article

  • Android parse XML documents using PULL 2010-12-14

    Android PULL technical analysis used in the system than using SAX XML documents much better technical performance. Android developers proposed technical parsing XML documents using PULL. SAX with similar, but the return type of event PULL technology

  • How To Read and Write XML Documents with GDataXML 2012-07-03

    In my recent post on How To Choose the Best XML Parser for Your iPhone Project, Saliom from the comments section suggested writing a post on how to use an XML library to read and write XML documents, create your own objects based on the documents, an

  • XML documents using Libxml2 operation 2010-02-25

    1, Libxml2 Description: Libxml2 is an xml parser c-language version, was originally a tool for the Gnome project development, based on the MIT License is a free open source software. It addition to supporting the c-language version, it also supports

  • (Transfer) the use of PL / SQL DOM API parsing of XML documents 2010-04-17

    This program demonstrates the use of PL / SQL DOM API for parsing XML documents, - Use the SYS.XMLDOM and SYS.XMLPARSER package - Program Analysis of the input XML file, print the document for all elements and element attributes connect scott / tiger

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.433 (s). 12 q(s)