当前位置:编程学习 > JS >>

jsp中如何调用dwr

1、首先需要引入dwr.jar包到工程中的lib中;2、在web.xml中配置dwr,如下:<!—— DWR配置 ——>

  <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、然后在WEB-INF下创建一个dwr.xml,并在里面将调用处理类配置,例如:<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、然后在需要调用的jsp中,将调用处理js类引入,如下:<% String contextPath = request.getContextPath();%> <script type='text/javascript' src='<%=contextPath %>/dwr/inte易做图ce/GetDataBaseRes.js'></script> <script type='text/javascript' src='<%=contextPath %>/dwr/engine.js'></script> <script type='text/javascript' src='<%=contextPath %>/dwr/util.js'></script>

  调用的js例子如下: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、如果需要在dwr调用类中获得session,或者request,如下:org.directwebremoting.WebContext wc = org.directwebremoting.WebContextFactory.get();HttpSession session = wc.getSession();HttpServletRequest request = wc.getHttpServletRequest();

 作者 sdtarena
 

补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,