DWR is a framework. Simply put, it can directly call java methods in javascript without having to write a lot of javascript code. It is implemented based on ajax and can achieve no refreshing effect. Many DWR examples, but most of them are just some method calls. They only introduce DWR at the usage level, and do not involve more technologies and design how javascript calls. DWR is a framework. Simply put, it can directly call java methods in javascript without having to write a lot of javascript code. It is implemented based on ajax and can achieve no refreshing effect.
There are many DWR examples on the Internet, but most of them are just some method calls. This article only introduces DWR at the usage level and does not involve more technologies and designs, the objective is to allow beginners to quickly learn how various java methods are called in javascript.
1. web. xml in dwr Configuration
1. Minimum Configuration
dwr-invoker
uk.ltd.getahead.dwr.DWRServlet
dwr-invoker
/dwr/*
2. When you want to view the test page (Using debug/test mode) automatically generated by DWR, you can add
debug
true
The default value of DWR is false. If you select true, you can view each deployed dwr class through http: // localhost: port/app/DWR. You can also test whether each method of java code runs normally. For security consideration, you must set this parameter to false in the official environment.
3. configuration of multiple dwr. xml files
There may be several situations, which we will list one by one. One servlet contains multiple dwr. xml configuration files. Multiple servlets correspond to one or more dwr. xml configuration files.
3.1. One servlet, multiple dwr. xml configuration files
dwr-invoker
uk.ltd.getahead.dwr.DWRServlet
config-1
WEB-INF/dwr1.xml
config-2
WEB-INF/dwr2.xml
In this configuration, the value of param-name must start with config. The number of param-names can be greater than or equal to 0. Without param-name, the WEB-INF/dwr. xml is read. If there are more than zero param-names, the WEB-INF/dwr. xml file will not be read.
3.2. Multiple servlets. Each servlet corresponds to one or more dwr. xml
dwr-invoker
uk.ltd.getahead.dwr.DWRServlet
dwr-invoker1
uk.ltd.getahead.dwr.DWRServlet
config-admin
WEB-INF/dwr1.xml
debug
true
dwr-invoker
/dwr/*
dwr-invoker1
/dwr1/*
In this case, we can control permissions based on J2EE security and add different roles for different URLs.
Ii. Usage of dwr
1. Call a JAVA method without return values or parameters
1.1. configuration of dwr. xml
Tags include things that can be exposed to javascript access.
The tag specifies the java class that can be accessed in javascript, and defines how DWR should obtain the instance of the class to be remote. Creator = "new" attribute specifies the java class instance generation method. new means that DWR should call the default constructor of the class to obtain the instance. Other methods include the spring method, by integrating with the IOC container Spring to obtain instances. The javascript = "testClass" attribute specifies the name used by the javascript code to access the object.
The tag specifies the java class name to be exposed to javascript.
Tag specifies the method to be exposed to javascript. If this parameter is not specified, all methods are exposed.
Label specifies the method to prevent access.
1.2 calls in javascript
First, introduce javascript scripts