About Java--dwr

Source: Internet
Author: User

"Define DWR":

DWR (Direct Web Remoting) is a remote server-side AJAX open-source framework for improving WEB pages to interact with Java classes.DWRtook a similarAJAXa new way to dynamically generateJAVAClass ofJavaScriptCode.thisWEBdevelopers will be able toJavaScriptused inJavacode as if they were local code of the browser(Client Code)same;butJavacode runs onWEBserver-side and free to accessWEBresources for the server.For reasons of safety, the WEBdevelopers have to properly configure whichJavaclasses can be safely used externally.

It consists of two main parts:

1. Allow JavaScript to get data from a servlet in the Web server that adheres to the Ajax principles.

2, JS Library can help developers to successfully use the data obtained to dynamically change the content of the Web page.

"Using DWR"

1, first must have the DWR jar package file: (Provide download path: Dwrjar file download)

2. Configure Dwr in Web. xml:

<!--configuring DWR--><servlet><servlet-name>dwr-invoker</servlet-name><servlet-class> org.directwebremoting.servlet.dwrservlet</servlet-class></servlet><servlet-mapping>< servlet-name>dwr-invoker</servlet-name><url-pattern>/dwr/*</url-pattern></ Servlet-mapping>
3. Create the class Adjbudgetmodel, and then create the method you want in the class:

/** * Used on the tree above the action by Xihy handling the dynamic processing of the interface event 2010-05-11 */public adjbudgetplaninfo gainthebootinfo (String bootid) throws Excepti on{/** * Query root node record */try{return treebugetdao.gainthebootinfo (bootid);} catch (Exception e) {e.printstacktrace (); return null;}}

4. adjbudgetplaninfo file

Package Com.xx.xx.budget.domain;public class Adjbudgetplaninfo {private String   bpiid                   ;p rivate string   Bctid                   ;p rivate string   bacid                   ;p rivate string   depid                   ;}        **ps: Here shorthand, there are some fields are not written out, and the corresponding set and get are not written out, here is just shorthand, then you can according to the needs of their own projects to improve


4. Create the Dwr.xml file and configure the class you just createdAdjbudgetmodel

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE dwr public    "-//getahead limited//dtd Direct Web Remoting 2.0//en"    "HTTP://GETAHEAD.ORG/DWR/DWR20.DTD" ><dwr><allow> <create creator= "Spring" javascript= "Adjbudgetserver" >                <param name= " Beanname "    value=" Adjbudgetmodel "/>        </create>
<!--returns him as an object to the client---        <convert match= "com.xx.xx.budget.domain.AdjBudgetPlanInfo" converter= "Bean" >       <param name= "include" value= "bpiid,bpiname,bpiisroot,haschildren,bpicreatedate,bpscid,bacid,proid, Bpilevel "></param>    </convert>      <convert match=" java.lang.Exception "converter=" Exception ">    <param name= ' include ' value= ' message '/>    </convert></allow></dwr>
5. Use in JSP pages

First introduced on your JSP page, the name introduced is the one that was configured in the XML file just now.

    
{PS: Here we are only responsible for the introduction, here is DWR introduced through the reflection mechanism.}

Then there is the use on the page:

function Startt () {<%if (null! = value &&!value.equals ("")) {%>adjbudgetserver.gainthebootinfo (' <%= Value%> ', {exceptionhandler:function (msg) {alert (msg);},callback:showsub}); <%}else{%>alert (' xxx '); <% }%>}

: The above is what I used in the project


About Java--dwr

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.