首先需要引入dwr
jar包到工程中的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)value;
var dataStr = ;
var arr = documentgetElementsByName(checkboxData)
for(var i=;i<arrlength;i++)
{ 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()
更多更全的jsp资讯尽在博洋教育您有任何jsp程序设计培训疑问欢迎咨询在线老师