and analysis of the use of DWR

sponsored links
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>
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of and analysis of the use of DWR


    dsfdsa Tomcat 6 with the connection pool data source configuration project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent Entries
Tag Cloud
Random Entries