How to call dwr in jsp

Source: Internet
Author: User

1. Introduce the dwr. jar package to lib in the project. 2. Configure dwr in web. xml as follows: <! -- DWR configuration -->

<Servlet>

<Servlet-name> dwr-invoker </servlet-name>

<Servlet-class> org. directwebremoting. servlet. DwrServlet </servlet-class>

<Init-param>

<Param-name> scriptCompressed </param-name>

<Param-value> false </param-value>

</Init-param>

</Servlet>

<Servlet-mapping>

<Servlet-name> dwr-invoker </servlet-name>

<Url-pattern>/dwr/* </url-pattern>

</Servlet-mapping>

3. Create a dwr. xml, and the processing class configuration will be called in it, for example: <dwr> <allow> <convert match = "com. po. oneSearchDto "converter =" bean "> <param name =" include "value =" resname, resid "> </param> </convert>

<Create javascript = "GetDataBaseRes" creator = "new"> <param name = "class" value = "com. util. getDataBaseRes "> </param> <include method =" getDataBaseRes "/> </create>

</Allow> </dwr>

4. Then, introduce the call processing js class in the jsp to be called, as follows: <% String contextPath = request. getContextPath (); %> <script type = 'text/javascript 'src = '<% = contextPath %>/dwr/interface/GetDataBaseRes. js '> </script> <script type = 'text/javascript' src = '<% = contextPath %>/dwr/engine. js '> </script> <script type = 'text/javascript' src = '<% = contextPath %>/dwr/util. js'> </script>

An example of calling js is as follows: function query () {var keyWord = document. getElementById ("keyWord "). Value; var dataStr = ""; var arr = document. getElementsByName ("checkboxData"); for (var I = 0; I <arr. length; I ++) {if (arr [I]. checked) {dataStr + = "," + arr [I]. value;} GetDataBaseRes. getDataBaseRes (keyWord, dataStr, disPoseRes );

}

Function disPoseRes (str) {alert (str );}

5. If you need to obtain the session or request in the dwr call class, as follows: org. directwebremoting. webContext wc = org. directwebremoting. webContextFactory. get (); HttpSession session = wc. getSession (); HttpServletRequest request = wc. getHttpServletRequest ();

Author sdtarena
 

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.