Configuration of the DWR framework in Ajax

Source: Internet
Author: User
When configuring DWR, copy the following servlet to the Web. xml configuration file:
<! -- DWR Ajax configuration --> <servlet>
<Servlet-Name> DWR-invoker </servlet-Name>
<Servlet-class> UK. Ltd. getahead. DWR. dwrservlet </servlet-class>
<Init-param>
<Param-Name> config </param-Name>
<Param-value> WEB-INF/DWR. xml </param-value>
</Init-param>
<Init-param>
<Param-Name> debug </param-Name>
<Param-value> true </param-value>
</Init-param>
<Init-param>
<Param-Name> scriptcompressed </param-Name>
<Param-value> false </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>

Add fitler:
<! -- DWR fitler --> <servlet-mapping>
<Servlet-Name> DWR-invoker </servlet-Name>
<URL-pattern>/DWR/* </url-pattern>
</Servlet-mapping>

To configure the DWR. xml file, you can directly use the bean managed by spring:

<? XML version = "1.0" encoding = "gb2312"?>
<! Doctype DWR public "-// getahead limited // DTD direct Web remoting 1.0 //" http://www.getahead.ltd.uk/dwr/dwr10.dtd ">
<DWR>
<Allow>
<! -- Define your own bean, so you need to convert it, otherwise you don't know -->
<Convert match = "com. sillycat. Core. model. User" converter = "Bean"/>
<! -- The capitalized usermanager is the JS name called on the page -->
<Create creator = "Spring" javascript = "usermanager">
<! -- Usermanager in lower case is the bean name managed by spring -->
<Param name = "beanname" value = "usermanager"/>
<! -- The method exposed by Ajax should only expose some safe methods... -->
<Include method = "getalluser"/>
<Include method = "getuser"/>
<Include method = "saveuser"/>
<Include method = "removeuser"/>
</Create>
</Allow>
</DWR>

When using the page, import three JS files: <SCRIPT type = 'text/JavaScript'
Src = '<% = request. getcontextpath () %>/DWR/interface/usermanager. js'> </SCRIPT>
<SCRIPT type = 'text/JavaScript'
Src = '<% = request. getcontextpath () %>/DWR/engine. js'> </SCRIPT>
<SCRIPT type = 'text/JavaScript'
Src = '<% = request. getcontextpath () %>/DWR/util. js'> </SCRIPT>

JS: function checkuserexist ()...{
If ($ ("logonname"). value = NULL | $ ("logonname"). value = "")...{
Loginnamemessage. innerhtml = "Enter the login name! ";
Return false;
}
Dwrutil. useloadingmessage ("checking .....");
Usermanager. istuserexistbylogonname (usercheckresult, $ ("logonname"). value );
}
 
Function usercheckresult (data )...{
If (Data = true )...{
// Alert ("adsfasdfasdf ");
Document. getelementbyid ("userexistflag"). value = 1;
Loginnamemessage. innerhtml = "the user name has been used! ";
} Else ...{
Alert ("adsfasdf ");
Loginnamemessage. innerhtml = "";
Document. getelementbyid ("userexistflag"). value = "0 ";
}
}

The JS that calls Ajax is:
Usermanager. istuserexistbylogonname (usercheckresult, $ ("logonname"). value );
Usermanager is the JS name. The first parameter is the callback function, and the last parameter is the parameter of the called method.

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.