Call of various java methods in DWR _ javascript tips-js tutorial

Source: Internet
Author: User
DWR is a framework. Simply put, it can directly call java methods in javascript without having to write a lot of javascript code. It is implemented based on ajax and can achieve no refreshing effect. Many DWR examples, but most of them are just some method calls. They only introduce DWR at the usage level, and do not involve more technologies and design how javascript calls. DWR is a framework. Simply put, it can directly call java methods in javascript without having to write a lot of javascript code. It is implemented based on ajax and can achieve no refreshing effect.

There are many DWR examples on the Internet, but most of them are just some method calls. This article only introduces DWR at the usage level and does not involve more technologies and designs, the objective is to allow beginners to quickly learn how various java methods are called in javascript.

 1. web. xml in dwr Configuration

1. Minimum Configuration

  
  
   dwr-invoker
   
  
   uk.ltd.getahead.dwr.DWRServlet
  
 
  
  
   dwr-invoker
   
  
   /dwr/*
  
 

2. When you want to view the test page (Using debug/test mode) automatically generated by DWR, you can add

  
  
   debug
   
  
   true
  
 

The default value of DWR is false. If you select true, you can view each deployed dwr class through http: // localhost: port/app/DWR. You can also test whether each method of java code runs normally. For security consideration, you must set this parameter to false in the official environment.

  3. configuration of multiple dwr. xml files

There may be several situations, which we will list one by one. One servlet contains multiple dwr. xml configuration files. Multiple servlets correspond to one or more dwr. xml configuration files.

  3.1. One servlet, multiple dwr. xml configuration files

  
  
   dwr-invoker
   
  
   uk.ltd.getahead.dwr.DWRServlet
   
    
   
    config-1
     
   
    WEB-INF/dwr1.xml
    
   
    
   
    config-2
     
   
    WEB-INF/dwr2.xml
    
  
 

In this configuration, the value of param-name must start with config. The number of param-names can be greater than or equal to 0. Without param-name, the WEB-INF/dwr. xml is read. If there are more than zero param-names, the WEB-INF/dwr. xml file will not be read.

  3.2. Multiple servlets. Each servlet corresponds to one or more dwr. xml

  
  
   dwr-invoker
   
  
   uk.ltd.getahead.dwr.DWRServlet
  
 
  
  
   dwr-invoker1
   
  
   uk.ltd.getahead.dwr.DWRServlet
   
    
   
    config-admin
     
   
    WEB-INF/dwr1.xml
    
   
    
   
    debug
     
   
    true
    
  
 
 
  
   dwr-invoker
   
  
   /dwr/*
  
 
  
  
   dwr-invoker1
   
  
   /dwr1/*
  
 

In this case, we can control permissions based on J2EE security and add different roles for different URLs.

Ii. Usage of dwr

1. Call a JAVA method without return values or parameters

1.1. configuration of dwr. xml

 
  
   
   
  
 

Tags include things that can be exposed to javascript access.

The tag specifies the java class that can be accessed in javascript, and defines how DWR should obtain the instance of the class to be remote. Creator = "new" attribute specifies the java class instance generation method. new means that DWR should call the default constructor of the class to obtain the instance. Other methods include the spring method, by integrating with the IOC container Spring to obtain instances. The javascript = "testClass" attribute specifies the name used by the javascript code to access the object.

The tag specifies the java class name to be exposed to javascript.

Tag specifies the method to be exposed to javascript. If this parameter is not specified, all methods are exposed.

Label specifies the method to prevent access.

 1.2 calls in javascript

First, introduce javascript scripts

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.