Introduction to DWR

Source: Internet
Author: User

1. Import Three jar packages:
Commons-validator-1.1.4.jar
Jakarta-oro-2.0.8.jar
DWR. Jar
2. modify the configuration file of Web. xml
<Servlet>
<Servlet-Name> DWR-invoker </servlet-Name> -------------------------- servletname
<Servlet-class> UK. Ltd. getahead. DWR. dwrservlet </servlet-class> ----- fixed value
<Init-param>
<Param-Name> debug </param-Name> ------- whether debugging is required
<Param-value> true </param-value>
</Init-param>
</Servlet>
<Servlet-mapping>
<Servlet-Name> DWR-invoker </servlet-Name>
<URL-pattern>/DWR/* </url-pattern> -------- requests from the Servlet
</Servlet-mapping>
3. Compile common Java background code
4. Write the class to be exposed to the front-end into the DWR. xml configuration file.
Make the following configuration under the allow node:
<Create creator = "new" javascript = "Demo"> ----- name required for calling the class on the foreground, for example, demo
<Param name = "class" value = "com. bluedot. Demo"/> ----- location of the class
</Create>
<Convert converter = "Bean" match = "com. bluedot. User"/> ----- if the returned value is a custom object, write the row.
5. test:
You can enter the path under the project name in the browser to view all the methods that can be called at the front-end when classes configured in DWR are exposed:
Example: http: // localhsot: 8080/dwrdemo/DWR
6. Foreground call:
Import JS files (usually at least 3)
<SCRIPT type = "text/JavaScript">
Function Update (){
VaR name = DWR. util. getvalue ("demoname"); ----------- get the value of the input field in the form
Demo. sayhello (name, function (data) {----------------- The name parameter is the parameter of the sayhello method in the demo class, and function {} is the callback function.
DWR. util. setvalue ("demoreply", data );
});
Demo. Say (function (User) {---------------- when the called method does not have an input parameter, only one callback method is passed.
Alert (user. ID );
Alert (user. Name );
Alert (user. Birthday );
});
VaR OBJ = new object (); ----------------- when the called method is a custom object, the DWR framework transmits the JS object to the background in JSON format.
OBJ. ID = 2;
OBJ. Name = 'wang wu ';
Demo. saysay (OBJ, function (data ){
Alert (data );
});
}
</SCRIPT>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.