Summary of the dwr getting started tutorial and the dwr getting started tutorial

Source: Internet
Author: User

Summary of the dwr getting started tutorial and the dwr getting started tutorial

Dwr: http://www.directwebremoting.org/dwr/downloads/index.html

In addition to a commons-logging-1.2.jar,

Put dwr. jar and commons-logging-1.2.jar in lib.

Let's take a look at an entry-level teaching material,

Http://www.cnblogs.com/cyjch/archive/2012/02/16/2353758.html, this write is very simple, according to the configuration can be achieved.

1. entity User

Package iwco. entity; public class User {// Login ID, the only private String id of the primary key; // name private String name; // password private String password; // email private String email; public String getId () {return id;} public void setId (String id) {this. id = id;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getPassword () {return password;} public void setPassword (String password) {this. password = password;} public String getEmail () {return email;} public void setEmail (String email) {this. email = email ;}}

2. DWRUserAccess class

package iwco.dwrs;import iwco.dao.UserDAO;import iwco.entity.User;public class DWRUserAccess {UserDAO userDAO = new UserDAO();     public boolean save(User user) {      return userDAO.save(user);    }    public User find(String id) {      return userDAO.find(id);    }}

3. Add the following content to the WEB. xml file:

<servlet>  <display-name>DWR Servlet</display-name>  <servlet-name>dwr-invoker</servlet-name>    <servlet-class>org.directwebremoting.servlet.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>

4. Add dwr. xml below the WEB-INF/as follows:

<!DOCTYPE dwr PUBLIC    "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"    "http://getahead.org/dwr/dwr30.dtd"><dwr>  <allow>    <create creator="new" javascript="JDate">      <param name="class" value="java.util.Date"/>    </create>    <create creator="new" javascript="DWRUserAccess">      <param name="class" value="iwco.dwrs.DWRUserAccess"/>    </create>    <convert converter="bean" match="iwco.entity.User"/>  </allow></dwr>

52.16test.html page

<! DOCTYPE html> Project organization diagram:


Then, allow the project and open the browser for testing. Let's take a look at it. I used it a long time ago. It Feels simple and I know the principle. However, a colleague asked me the day before yesterday, asking me to configure one. At that time, I wanted to complete it. Later I thought there were a lot of introductory teaching materials. But if you think about it carefully, you can record it and ask the connection address directly.

1. Add three js files on the jsp page:

<script src="/dwrTest/dwr/engine.js"></script><script src="/dwrTest/dwr/util.js"></script><script src="/dwrTest/dwr/interface/DWRUserAccess.js"></script>
The first two did not say that dwr comes with js, and the third is our own. People who just came into contact must be confused. In fact, it's easy to understand. We have the configuration in dwr:

 <create creator="new" javascript="DWRUserAccess">      <param name="class" value="iwco.dwrs.DWRUserAccess"/>    </create>
The file name of the third js is the javascript value, and it is the directory starting with dwr/interface.

2. create nodes in dwr. xml. creator can be configured in several ways:

New: Java uses the "new" keyword to create an object

None: it does not create an object (v1.1 +)

Scripted: creates an object through BSF using a scripting language, such as BeanShell or Groovy

Spring: Access Bean through Spring framework

Struts: Use Struts FormBean (v1.1 +)

Jsf: Bean using JSF (v1.1 +)

Pageflow: access the PageFlow (v1.1 +) of Weblogic or Beehive)

Ejb3: Use EJB3 session bean (v2.0 +)

The above example uses new, and many projects now use Spring, so I gave a spring:

<Create creator = "spring" javascript = "backUpDocumentService"> <param name = "beanName" value = "testDWR1"/> <include method = "modifyBackUpFiles"> </include> <include method = "isSafeCodeRight"> </include> </create> <! -- Add include to specify specific methods in the java class, if this parameter is not added, all the methods in the default class are public --> <create creator = "spring" javascript = "testDWR2"> <param name = "beanName" value = "testDWR2"/> </create>

Add the following content to the corresponding spring file:
<bean id="testDWR1" class="com.test.testDWR1"></bean><bean id="testDWR2" class="com.test.testDWR2"></bean>
Of course, you can handle the annotation yourself.



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.