The simplest DWR configuration description
Configuration of DWR. xml
<DWR>
<Allow>
<Create creator = "new" javascript = "testclass">
<Param name = "class" value = "com. DWR. testclass"/> -----> -----〉****
<Include method = "testmethod1"/>
</Create>
<Convert converter = "Bean" match = "com. DWR. testbean"/>
</Allow>
</DWR>
Note:
<Allow> the tag contains things that can be exposed to JavaScript access.
<Create> the tag specifies the Java class that can be accessed in JavaScript and defines how DWR gets the instance of the class to be remotely implemented.
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. DWR can generate *. js files by itself, but we cannot see them within the project. Is an implicit Virtual File. This configuration generates testclass. js
<Param> label specifies the Java class name to be exposed to JavaScript.
<Include> the tag specifies the method to be exposed to JavaScript. If this parameter is not specified, all methods are exposed.
<Exclude> label specifies the method to prevent access.
<Convert> labels define the types of objects that can be returned by this class. to return an object, specify its type here.
The converter attribute is a written bean, and match is the class name of the returned object.
Calls in Javascript
First, introduce JavaScript scripts
<SCRIPT src = 'dwr/interface/testclass. js'> </SCRIPT>
<SCRIPT src = 'dwr/engine. js'> </SCRIPT>
<SCRIPT src = 'dwr/util. js'> </SCRIPT>
Testclass. JS is automatically generated by DWR according to the configuration file, and engine. js and util. js are built-in script files of DWR.
Second, write JavaScript Functions that call Java methods.
Function calltestmethod1 (){
Testclass. testmethod1 ();
}
Note:
* *** If you write it as <Param name = "class" value = "testclass"/>, this write means that this class is injected through spring in advance. Then, you must change it to <create creator = "Spring" javascript = "testclass">