首先需要引入dwrjar包到工程中的lib中在webxml中配置dwr如下<!—— DWR配置 ——>
<servlet>
<servletname>dwrinvoker</servletname>
<servletclass>orgdirectwebremotingservletDwrServlet</servletclass>
<initparam>
<paramname>scriptCompressed</paramname>
<paramvalue>false</paramvalue>
</initparam>
</servlet>
<servletmapping>
<servletname>dwrinvoker</servletname>
<urlpattern>/dwr/*</urlpattern>
</servletmapping>
然后在WEBINF下创建一个dwrxml并在里面将调用处理类配置例如<dwr> <allow> <convert match=compoOneSearchDto converter=bean> <param name=include value=resnameresid></param> </convert>
<create javascript=GetDataBaseRes creator=new> <param name=class value=comutilGetDataBaseRes></param> <include method=getDataBaseRes/> </create>
</allow> </dwr>
然后在需要调用的jsp中将调用处理js类引入如下<% String contextPath = requestgetContextPath()%> <script type=text/javascript src=<%=contextPath %>/dwr/interface/GetDataBaseResjs></script> <script type=text/javascript src=<%=contextPath %>/dwr/enginejs></script> <script type=text/javascript src=<%=contextPath %>/dwr/utiljs></script>
调用的js例子如下function query(){ var keyWord = documentgetElementById(keyWord)valuevar dataStr = var arr = documentgetElementsByName(checkboxData)for(var i=i<arrlengthi++){ if(arr[i]checked){ dataStr+=+arr[i]value} GetDataBaseResgetDataBaseRes(keyWorddataStrdisPoseRes)
}
function disPoseRes(str){ alert(str)}
如果需要在dwr调用类中获得session或者request如下orgdirectwebremotingWebContext wc = orgdirectwebremotingWebContextFactoryget()HttpSession session = wcgetSession()HttpServletRequest request = wcgetHttpServletRequest()