JavaScript calls Java methods--Steps to use the DWR framework __java

Source: Internet
Author: User

JavaScript calls Java method--dwr steps

1. Download Dwr.jar directly to your project under the Webroot/web-inf/lib package;

2. Re-modify Web.xml

<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <servlet-class> uk.ltd.getahead.dwr.dwrservlet</servlet-class>
  <init-param>
   <param-name>debug</ param-name>
   <param-value>true</param-value>
  </init-param>
 </servlet>
 <servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern >/dwr/*</url-pattern>
 </servlet-mapping>

Add to </web-app> before

3. Build a Dwr.xml file and copy the file under Web-inf

<! DOCTYPE dwr Public "-//getahead limited//dtd Direct Web Remoting 1.0//en"
"http://www.getahead.ltd.uk/dwr/ Dwr10.dtd ">
<dwr>
 <allow>  
  <create creator=" new "javascript=" Demo ">
   < Param name= "class" value= "Your.java.Bean"/>
  </create>  
 </allow>
</dwr> 

Description: A Java class for each DWR agent needs to be placed in <allow></allow>.

<createcreator= "new" javascript= "Demo" > javascript= is a name for The Java class referenced in the JSP, usually the same as the class name . Create= represents what type of Java, andnew represents a generic type.

<paramname= "Class" value= "Your.java.Bean"/> Class indicates that the demo is a normal class, and value represents the path (package name. Class name) that this class holds.

4. Build a class, write the method (I built here is a Hello Class)

Package Com.hello;
public class Hello {public
 string Hello (string name)
 {return
  ] hello. "+ Name +". Your first dwr. ";
 }
}

5. Build another hello jsp file.  

The picture after the appeal step is completed

6. If you have completed the first 5 steps,

Please enter the HTTP://LOCALHOST:8080/project name in the browser/dwr (not only the light to test the role) to see the interface is not the interface (see below), if you can come out to show that your efforts have not been wasted. Rattle.. Do not underestimate the page where the box will be used.


7. Copy the box in the above image to the JSP, as long as it is below <title></title>



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.