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