熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jsp中如何調用dwr

2022-06-13   來源: JSP教程 

  首先需要引入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()


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19678.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.