Use of the DWR framework

Source: Internet
Author: User

DWR is an AJAX framework, in the JS code can easily call Java class method, DWR and Ajax What difference, DWR configuration more, JS write less code, AJAX does not need any configuration, write code more

How do I use the DWR framework?

Download Dwr30.jar,common-logging.jar First, put it under Lib

Create a dwr.xml under Web-inf

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE dwr    Public " -//getahead limited//dtd Direct Web Remoting 3.0//en "    http://getahead.org/dwr/dwr30.dtd" ><dwr>    <allow>        <create creator= "new" javascript= "Dwrservice" >            <param Name= "class" value= " Com.chen.Chen "></param>        </create>    </allow></dwr>

Creator is created in New way, JavaScript represents a function called Java in the JS page identifier, param tag specifies the class that the identifier calls

The configuration in Web. XML is

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id= "Webapp_ ID "version=" 3.0 "> <servlet> <servlet-name>dwr-invoke</servlet-name> <servlet-class>org.directwebremoting.servlet.dwrservlet</servlet-class> <!--Configure DWR's debug functionality for easy testing, and when released, be sure to delete--<init-param> <param-name>debug</param- Name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-in Voke</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> <welcome-file-list> <WELCOME-FILE>INDEX.JSP&L T;/welcome-file> </welcome-file-list></web-app>

Java class

 Package Com.chen;  Public class Chen {    public  string getName (string name) {        System.out.println ("a");         return name + "abc";    }    }

Page

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding= "UTF-8"%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >var callservicemethod=function (obj) {//parameter 1 is a parameter that needs to be given to a Java class method//the last parameter is the callback methodDwrservice.getname (' abc '), function (data) {alert ("B") alert (data);        });    }; Callservicemethod ();</script>ABC</body>

Use of the DWR framework

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.