DWR 3.0 configuration + different parameters, different return values Call Method Example

Source: Internet
Author: User

Configuration method:

1 Official website Dwr.jar Package

2 Web

<!--DWR---<listener> <listener-class>org.directwebremoting.servlet.dwrlistener</ listener-class> </listener> <servlet> <servlet-name>dwr-invoker</servlet-name> <serv Let-class>org.directwebremoting.servlet.dwrservlet</servlet-class> <init-param> <description&    Gt;</description> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet>


3 Dwr.xml

A and Spring Integration

<dwr><allow><create creator= "Spring" javascript= "Dwrservice" ><param name= "BeanName" value= " Dwrserviceimpl "></param></create><create creator=" Spring "javascript=" BasicDwrService ">< param name= "beanname" value= "Basicdwrserviceimpl" ></param></create><convert match= " Com.ass.common.generated.model.TUser "converter=" Bean "/> </allow></dwr>

B No integration with spring


<dwr><allow><create creator= "new" javascript= "TestClass" ><param Name= "class" value= "/ Com.dwr.TestClass "/><include method=" TestMethod1 "/></create></allow></dwr>


4 JSP page reference

<script type= ' text/javascript ' src= "${root}dwr/engine.js" ></script><script type= ' Text/javascript ' src= "${root}dwr/util.js" ></script><script type= ' text/javascript ' src= "${root}dwr/interface/ Dwrservice.js "></script>


The above configuration is a bunch of online, the focus is below use example ******************************************************************** *********


1 JSP page notation and 2 background notation


1:

<script type= "Text/javascript" >function teststr () {console.info ("begin test str"); Dwrservice.teststr ("Wangt", function (data) {Console.info (data)}); Function testmap () {//*******map parameter notation 1 beginvar data = {u :  ' username ', p  :  ' password '}//*******map parameter 1 end//*******map parameter notation 2 beginvar d = new  Object ();d .name =  ' AA ';d. sdf= ' ss ';//*******map parameter notation 2 endconsole.info (d); console.info (data); Dwrservice.testmap (d, function (data) {console.info (data); Console.info (Data.ok);})} Function testshuzu () {Var a = new array ();a[0] =  "1";a[1] =  "2"; a[ 2] =  "3";d wrservice.testshuzu1 (a,function (d) {//return string[]console.info (d); Console.info (D[0] );}) DWRSERVICE.TESTSHUZU2 (A,function (d) {//return list<string>console.info (d); Console.info (D[0]);})} Function testlist () {VAR&NBSP;LST&NBSP;=&NBSP;[];//VAR&NBSP;A&NBSP;=&NBSP;{NAME&NBSP;:&NBSP; " Aname ", password:  ' Paassword '};//var b = {name : " bname ",  password:   ' bpassword '};var a = new object (); Var b = new object (); a.name  =  "Aname";a.password =  "Apassword";b.name =  "bname";b.password =  " Bpassword "; Lst[0] = a;lst[1] = b;console.info (LST);d wrservice.testlist (Lst, function ( DA) {console.info (DA); Console.info (da[0]); Console.info (Da[0].ok);})} Function testuser () {var u = new object (); u.name= "uname";d wrservice.testuser (U, function (d) {console.info (d); Console.info (d.name);})} </script>




2 Java code

@Overridepublic  string teststr (STRING&NBSP;STR)  {system.out.println (str);return  "Hello" + STR;} /* *  *  @see  com.ass.common.service.dwrservice#testmap (JAVA.UTIL.MAP)  * @ author wangt 2014 December 1   morning 10:51:08  */@Overridepublic  map<string, string > testmap (map<string, string> m) {System.out.println (M); System.out.println (M.get ("U")); System.out.println (M.get ("P")); Map<string, string> m1 = new hashmap<string, string> ();  m1.put ( "OK",  "Is ok"); return m1;} /* *  *  @see  com.ass.common.service.dwrservice#testshuzu1 (java.lang.String[])  *   @author  wangt 2014 December 1   morning 10:51:08  */@Overridepublic  String[]  TESTSHUZU1 (string[] s) {System.out.println (s); System.out.println (S[1]); string[] c = {"AA", "VV", "CC"};RETURN&NBSP;C;} /* *  * @see  com.ass.common.service.dwrservice#testshuzu2 (java.util.List)  *  @author  wangt  December 1, 2014   morning 10:51:08  */@Overridepublic  list<string> testshuzu2 (list<string > l) {System.out.println (L); System.out.println (l.get (0)); List<string> ll = new arraylist<string> (); Ll.add ("AA"); Ll.add ("BB"); return  ll;} /* *  *  @see  com.ass.common.service.dwrservice#testlist (java.util.List)  * @ author wangt 2014 December 1   Morning 10:51:08  */@Overridepublic  list<map<string, String>> testlist (list<map<string, string>> l) {System.out.println (l.get (0)); Map<string, string> m1 = new hashmap<string, string> (); Map< String, string> m2 = new hashmap<string, string> ();  m1.put ("OK",   "Okoko"); M1.put ("Oooo",  "oooo"); M2.put ("OK",  " Okoko222 "); M2.put (" Oooo ", " oooo222 "); list<map<string, string>> ll = new arraylist<map<string,  String>> (); Ll.add (M1); Ll.add (m2); return ll;} /* *  *  @see  com.ass.common.service.dwrservice#testuser ( Com.ass.common.generated.model.TUser)  *  @author  wangt 2014 December 1   Morning 10:51:08   */@Overridepublic  tuser testuser (tuser m) {System.out.println (M.getname ()); Tuser c = new tuser (); C.setname ("AAA"); return c;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

DWR 3.0 configuration + different parameters, different return values Call Method Example

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.