First of all, after we configure Dwr3, we can test it in the browser to check whether the Dwr we configured is effective. The method is
http://localhost:[Your server port number is not written as 80 by default]/[Web name]/dwr/. After pressing, the name of the Dwr script you defined earlier will appear, as shown below:
When you click on the first remote, the following page will appear:
The appearance of such a page means that your Dwr basic configuration is successful. Why is it basically successful? Because it shows all the methods of your Service component, but one thing is that only if you annotate the @RemoteMethod method, you have permission to access it directly on the page, otherwise an error will be reported;
Then we can really use the page to access the background method. Before that, you must introduce the following three files into the *.html file contained in your *.js file, as shown below:
<scripttype='text/javascript'src='WebPath/dwr/engine.js'></script><scripttype='text/javascript'src='WebPath/dwr/util.js'></script>
The above is what Dwr must refer to by default, and the principle is not explained. The following is the Service component (class in Java) you want to call, which is equivalent to a Js file. That is to say, Dwr converts the Service class on the backend directly into a front-end js file. The method inside is equivalent to the method in this js file. As long as it is referenced, it can be called directly, as shown below:
<scripttype='text/javascript'src='WebPath/dwr/interface/remote.js'></script>
Then you can directly call the methods in the remote class in our js, as shown below:
(function($){remote.setEnableDwrUpdate();};The setEnableDwrUpdate() in remote is the setEnableDwrUpdate() method in the SessionExpiredParam class in the previous article;
At this point, the front-end calls the back-end is OK. The next article is how to reversely call the front-end, so I will give you spoilers in advance ^_^;