jsp

位置:IT落伍者 >> jsp >> 浏览文章

jsp中如何调用dwr


发布日期:2023年03月06日
 
jsp中如何调用dwr

首先需要引入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(keyWordvaluevar dataStr = var arr = documentgetElementsByName(checkboxDatafor(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()

               

上一篇:在JSP环境中如何配置和使用fckeditor

下一篇:在JSP中访问数据库大全