2. Modify web.xml file, add the mapping DWRServlet
<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>
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" "http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<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">
<html>
<head>
<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>
<body>
<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 Demo.java. 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 Demo.java.
HTML source:
<p>
Name:
<input type="text"/>
<input value="Send" type="button"/>
<br/>
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;
)
)
dwr.xml
<? xml version = "1.0" encoding = "UTF-8"?>
<! DOCTYPE dwr PUBLIC
"- / / GetAhead Limited / / DTD Direct Web Remoting 2.0 / / EN"
"http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="Demo">
<param name="class" value="org.getahead.dwrdemo.simpletext.Demo"/>
</ create>
</ allow>
</ dwr>







