DWR is a framework that is easy in javascript can call java methods directly, without having to go to write a lot of javascript code. Its implementation is based on the ajax, you can achieve the effect without refresh.

DWR has a number of online examples, but most just call one way or another, this article only in the introduction on the use of level DWR, are not related to more technical and design, its purpose is to allow beginners can quickly learn to a variety of java Ways in how javascript calls.

In this paper, based on DWR 1.1 for DWR 2.0, because there are no official release, so no introduction.

1, DWR configuration of web.xml articles

1, the smallest configuration

<servlet>
<servlet-name> dwr-invoker </ servlet-name>
<servlet- class> uk.ltd.getahead.dwr.DWRServlet </ servlet-class>
</ servlet>
<servlet-mapping>
<servlet-name> dwr-invoker </ servlet-name>
<url-pattern> / dwr / * </ url-pattern>
</ servlet-mapping>
2, when we want to see DWR automatically generated test page (Using debug / test mode) can be added in the servlet configuration

<init-param>
<param-name> debug </ param-name>
<param-value> true </ param-value>
</ init-param>

DWR default this parameter is false. If you choose true, we can http://localhost:port/app/dwr to see each of you to deploy DWR class. Java code and can test whether each method is working correctly. For security reasons, in a formal environment you must put this parameter is set to false.

3, a number of configuration files dwr.xml

There are several possible situations, we added to the list. A servlet, a number of configuration files dwr.xml; multiple servlet, each corresponding to one or more servlet configuration file dwr.xml.

3.1, a servlet, a number of configuration files dwr.xml

<servlet>
<servlet-name> dwr-invoker </ servlet-name>
<servlet- class> uk.ltd.getahead.dwr.DWRServlet </ servlet-class>
<init-param>
<param-name> config-1 </ param-name>
<param-value> WEB-INF/dwr1.xml </ param-value>
</ init-param>
<init-param>
<param-name> config-2 </ param-name>
<param-value> WEB-INF/dwr2.xml </ param-value>
</ init-param>
</ servlet>

In this configuration, param-name value must be at the beginning of config. param-name can have> = 0. If no param-name, it will be read WEB-INF/dwr.xml. If there is more than zero param-name, then WEB-INF/dwr.xml document will not be read.

3.2, a number of servlet, each corresponding to a servlet or more dwr.xml

<servlet>
<servlet-name> dwr-invoker </ servlet-name>
<servlet- class> uk.ltd.getahead.dwr.DWRServlet </ servlet-class>
</ servlet>
<servlet>
<servlet-name> dwr-invoker1 </ servlet-name>
<servlet- class> uk.ltd.getahead.dwr.DWRServlet </ servlet-class>
<init-param>
<param-name> config-admin </ param-name>
<param-value> WEB-INF/dwr1.xml </ param-value>
</ init-param>
<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>
<servlet-mapping>
<servlet-name> dwr-invoker1 </ servlet-name>
<url-pattern> / dwr1 / * </ url-pattern>
</ servlet-mapping>

Under such circumstances, we can according to J2EE security to control the permissions for different url, add a different role.