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>