DWR (1)

Source: Internet
Author: User



<Param-Name> debug </param-Name>

<Param-value> true </param-value>


Resolution: <init-param>

Parameters in the servlet range can only be obtained in the servlet Init () method. The configuration in Web. XML is as follows:


<Servlet-Name> mainservlet </servlet-Name>

<Servlet-class> com. Wes. Controller. mainservlet </servlet-class>


<Param-Name> param1 </param-Name>

<Param-value> avalible in servlet Init () </param-value>


<Load-on-startup> 0 </load-on-startup>


In servlet, you can use the following code:

Package com. Wes. Controller;

IMPORT javax. servlet. servletexception;

IMPORT javax. servlet. http. httpservlet;

Public class mainservlet extends httpservlet ...{


Public mainservlet ()...{

Super ();


Public void Init () throws servletexception ...{

System. Out. println ("the following two parameters param1 are stored in servlet ");
System. Out. println (this. getinitparameter ("param1 "));

System. Out. println ("the following parameters are stored in servletcontext ");
System. Out. println (getservletcontext (). getinitparameter ("context/Param "));



Parameters can only be obtained through this. getinitparameter ("param1") in the servlet Init () method.


<URL-pattern>/DWR/* </url-pattern>

Resolution: It indicates that all files containing the WDR name when the project is started will be called here.


<Create javascript = "hello" creator = "new">
<Param name = "class" value = "com. Yinhe. Service. hellodwr"> </param>


Parse: javascript = "hello" Name the hellowdr class "hello" in JavaScript to call the data in the hellowdr class.

Creator = "new" is created in the form of new


<SCRIPT type ='Text/JavaScript'Src ='/DWR/engine. js'> </SCRIPT>

<SCRIPT type ='Text/JavaScript'Src ='/DWR/interface/Hello. js'> </SCRIPT>

<SCRIPT type ='Text/JavaScript'Src ='/DWR/util. js'> </SCRIPT>

Resolution: The three items are directly copied to the JSP file displayed on the successfully tested page.


Hello. gethello (username, callback );

The Hello. gethello parameter in JS has an additional callback parameter used to return data.


Note: prompts in JS to call the methods in the hellowdr class are not prompted by callback.

Write by 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.