注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

zhouhaigang.love的博客

喜欢冬日黄昏那冻住的山

 
 
 

日志

 
 

dwr的用法  

2008-03-16 16:42:37|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

步骤

1.将dwr.jar放入lib文件中

2.在jsp页面中咖入引用

<script type='text/javascript' src='../../dwr/engine.js'> </script>

<script type='text/javascript' src='../../dwr/util.js'> </script>

<script type="text/javascript" src="../../dwr/interface/QueryFaultListHandler.js"></script>

前两个文件是必须包括的引擎文件

第三个文件是不固定的,每写一个java类,就要添加一个引用.这里是新建了一个名为QueryFaultListHandler的类

3.修改dwr.xml文件

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd ">

<dwr>

  <allow>

    <create creator="new" javascript="QueryFaultListHandler">

      <param name="class" value="com.ubi.rt.QueryFaultListHandler"/>

    </create>

  </allow>

</dwr>

4.在具体的jsp页面里根据dwr.xml中配置的对象的名字来引用java类

分两种情况:

<a>调用无返回值的方法:例如,在QueryFaultListHandler有一个confirmAllFault(key_uid);

那么在页面中可直接调用.

function deom(key_uid){

    QueryFaultListHandler.confirmAllFault(key_uid);

}

<b>有返回值的方法如何调用 ,例如在QueryFaultListHandler有一个confirmAllFault(key_uid);返回一个string类型

那么在页面中这样调用:

function demo(key_uid){

    QueryFaultListHandler.confirmAllFault(aaaa,key_uid);

}

function aa(str_return){

//这里的str_return就是confirmAllFault方法的返回值

}

在jsp页面中调用有返回在值的方法时,必须新建一个function();

在调用这个类的public的有返回值的方法时,把新建的function名当做第一个参数转入,以便在这个函数中得到返回数进行处

附源代码:

java类

------------------------------------------------------------------------------------------ -----------------------

/*

 * Created on 2005-9-8

 *

 * TODO To change the template for this generated file go to

 * Window - Preferences - Java - Code Style - Code Templates

 */

package com.ubi.rt;

import java.util.Vector;

import com.ubi.util.db.DAO;

import com.ubi.util.db.DAOFactory;

import com.ubi.util.db.table.T_Dynamic_event_17;

/**

 * @author Allen

 *

 * TODO To change the template for this generated type comment go to Window -

 * Preferences - Java - Code Style - Code Templates

 */

public class QueryFaultListHandler {

    public String confirmAllFault(Integer key_uid) {

        try {

            DAO dao = DAOFactory.getDAO("Dynamic_event_17");

            String sql = " datediff(dd,event_occur_time,getdate())<1 and resource_type_uid = 4 and resource_uid ="

                    + key_uid.intValue() + " group by event_level order by event_level";

            Vector vct_fault = dao.select(sql);

            T_Dynamic_event_17 tde = null;

            for (int i = 0; i < vct_fault.size(); i++) {

                tde = (T_Dynamic_event_17) vct_fault.get(i);

                tde.setFault_state(new Integer(2));

                dao.update(tde, tde.getDynamic_event_uid());

            }

        } catch (Exception ex) {

            ex.printStackTrace();

            return "bed";

        }

        return "ok";

    }

}

jsp文件

---------------------------------------------------------------------------------------------------------------------------

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts- logic.tld" prefix="logic"%>

<%@ taglib uri="/WEB-INF/struts- template.tld" prefix="temp"%>

<%@page pageEncoding="GB2312"%>

<%request.setCharacterEncoding("GB2312");%>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<html:html locale="true"><html:base/>

<head>

<title>事件列表</title>

<link href="../../style/main.css" _fcksavedurl=""../../style/main.css"" rel="stylesheet" type="text/css">

<script src="../../js/seltime.js" language="JavaScript" type="text/JavaScript"></script>

<script type="text/javascript" src="../../scripts/httpObj.js"></script>

<script type='text/javascript' src='../../dwr/engine.js'> </script>

<script type='text/javascript' src='../../dwr/util.js'> </script>

<script type="text/javascript" src="../../dwr/interface/QueryFaultListHandler.js"></script>

<script>

var http = getHTTPObject();

function goToParent(key_uid,type_uid){

 var url ="././graphAction.do?method=viewSubNode&key_uid="+key_uid+"&type_uid="+type_uid;

 window.location = url;

}

function confrimFault(indexId,uid){

 showAddDataXxd(indexId,uid);

}

function confirmAllFault(key_uid){

 //sendRequestData(key_uid);

 changeTitle();

 QueryFaultListHandler.confirmAllFault(changeTab2,key_uid);

}

function viewKnowledge(key_uid,event_uid,fault_definition_type){

 url = "graphAction.do?method=viewKnowledge&key_uid="+key_uid+"&fault_definition_type_uid="+fault_definition_type+"&event_uid="+event_uid;

 window.open(url,'故障相关知识库信息','height=400, width=705, top=200, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');

}

function viewDetail(key_uid,uid,res_mon_pnt_inst_event_uid,fault_type_uid,fault_level){

 url = "graphAction.do?method=viewDetail&key_uid="+key_uid+"&res_mon_pnt_inst_event_uid="+res_mon_pnt_inst_event_uid+"&fault_definition_type_uid="+fault_type_uid+"&event_uid="+uid+"&fault_level="+fault_level;

 window.open(url,'故障详细信息','height=400, width=705, top=200, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no');

 //alert('aa');

}

function changeTitle(){

 var tab = document.getElementById ("tab");

 var rs = tab.rows;

 var r = rs[rs.length-1];

 var cs = r.cells;

 cs[1].innerHTML="<font color=#cccccc>...请稍候...</font>";

 //alert('ok');

}

function sendRequestData(uid){

 alert("开始处理");

 alert(uid);

 var requestDataXxdFunctionId =105;//定义function

 alert("m"+m);

 alert(requestDataXxdFunctionId);

 http.open("GET", "../../rtss?function="+requestDataXxdFunctionId+"&uid="+uid);

 http.onreadystatechange = function(){ 

  if (http.readyState == 4) {

   changeTab2();

  }

 }

 http.send(null);

}

function showAddDataXxd(inde,uid){  

 

 var requestDataXxdFunctionId =104;//定义function

 http.open("GET", "../../rtss?function="+requestDataXxdFunctionId+"&uid="+uid);

 http.onreadystatechange = function(){ 

  if (http.readyState == 4) {

   changeTab(inde);

  }

 }

 http.send(null); 

}

function changeTab2(returnStr){

 if(returnStr=='ok'){

  var tab = document.getElementById("tab");

  var rs = tab.rows;

  var reCount = (rs.length-3)/2;

  //alert("总行数"+reCount);

  for(var i=0;i<reCount;i++){

   //alert("当前循环到"+i);

   var curIndex = i*2+2;

   //alert("记录所在行"+curIndex);

   var r = rs[curIndex];

   var cs =r.cells;

   //alert("该行所有单位格数"+cs.length);

   if(cs!=null&&cs.length==7){

    cs[4].innerHTML='已确认';

   }

  }

  var r = rs[rs.length-1];

  var cs = r.cells;

  cs[1].innerHTML="<font color=#cccccc>已全部确认</font>";

 }

 

 

}

function changeTab(ind){

 var tab = document.getElementById("tab");

 var rs = tab.rows;

 var curIndex = ind*2+2;

 var r = rs[curIndex];

 var cs =r.cells;

 cs[4].innerHTML='已确认';

}

</script>

<style type="text/css">

<!--

a:active {

 color: #183554;

}

.style1 {font-size: 12px}

-->

</style>

</head>

<body>

<center>

  <td>

   <table width="680" border="0" cellspacing="0" cellpadding="0" id="tab">

       <%=(request.getAttribute("hasNoItem")==null?"": request.getAttribute("hasNoItem"))%>

    <tr align="left">

      <td colspan="7" class="tdDataValue1">

      &nbsp;&nbsp;拓扑视图 &gt; 

      <logic:present name="node_name">

      <bean:write name="node_name" filter="false"/>

      </logic:present>

      &gt;

      <font color="#6699FF">查看故障列表</font></td>

        </tr>

    <tr>

     <td width="8%" class="tdListTitle">故障id</td>

     <td width="25%" class="tdListTitle">故障名称</td>

     <td width="14%" class="tdListTitle">故障级别</td>

     <td width="25%" class="tdListTitle">发生时间</td>

     <td colspan="3" class="tdListTitle">操作</td>

    </tr>

    <logic:present name="graphForm" property="job_vos">

    <logic:iterate id="v1" name="graphForm" property="job_vos" scope="request" indexId="ind">

    

    <tr onMouseOver="this.style.background='#EAE6DB' " onMouseOut="this.style.background=''">

     <td class="tdListdata1"><bean:write name="v1" property="dynamic_event_uid" filter="true"/></td>

     <td class="tdListdata1"><bean:write name="v1" property="event_name" filter="true"/></td>

     <logic:equal name="v1" property="event_level" value="4">

     <td class="tdListdata1" bgcolor="#FF0000">

     严重

     </td>

     </logic:equal>

     <logic:equal name="v1" property="event_level" value="3">

     <td class="tdListdata1" bgcolor="#FF00CC">

     主要

     </td>

     </logic:equal>

     <logic:equal name="v1" property="event_level" value="2">

     <td class="tdListdata1" bgcolor="#FF9900">

     普通

     </td>

     </logic:equal>

     <logic:equal name="v1" property="event_level" value="1">

     <td class="tdListdata1" bgcolor="#FFFF00">

     次要

     </td>

     </logic:equal>

     <td class="tdListdata1"><bean:write name="v1" property="event_occur_time" filter="true"/></td>

     <td width="9%" class="tdListdata1">

     <logic:notEqual name="v1" property="fault_state" value="2">

     <a href='javascript:confrimFault(<bean:write name="ind"/>,<bean:write name="v1" property="dynamic_event_uid" filter="true"/>)'>确认</a>

     </logic:notEqual>

     <logic:equal name="v1" property="fault_state" value="2">

     已确认

     </logic:equal>     

      </td>

        <td width="9%" class="tdListdata1"><a href='javascript:viewKnowledge(<bean:write name="graphForm" property="key_uid"/>,<bean:write name="v1" property="dynamic_event_uid"/>,<bean:write name="v1" property="fault_definition_type"/>)'>知识库</a></td>

        <td width="10%" class="tdListdata1"><a href='javascript:viewDetail(<bean:write name="graphForm" property="key_uid"/>,<bean:write name="v1" property="dynamic_event_uid"/>,<bean:write name="v1" property="res_mon_pnt_inst_event_uid"/>,<bean:write name="v1" property="fault_definition_type"/>,<bean:write name="v1" property="event_level"/>)'>查看详细</a></td>

    </tr>

    <tr>

     <td colspan="7" class="trLine"></td>

    </tr>

    </logic:iterate>

    </logic:present>

    <tr>

     <td height="25" colspan="4" align="left">

     当前共有告警

     <logic:present name="count_total">

     <font color="#FF0000">

     <bean:write name="count_total"/>

     </font>

     </logic:present>

     条 严重

     <logic:present name="count_level4">

     <font color="#FF0000">

     <bean:write name="count_level4"/>

     </font>

     </logic:present>

     主要

     <logic:present name="count_level3">

     <font color="#FF0000">

     <bean:write name="count_level3"/>

     </font>

     </logic:present>

     普通

     <logic:present name="count_level2">

     <font color="#FF0000">

     <bean:write name="count_level2"/>

     </font>

     </logic:present>

     次要

     <logic:present name="count_level1">

     <font color="#FF0000">

     <bean:write name="count_level1"/>

     </font>

     </logic:present>

     </td>

        <td height="25" colspan="3" align="center">

     <logic:present name="count_total">

     <logic:greaterThan name="count_total" value="0">

      <a href='javascript:confirmAllFault(<bean:write name="graphForm" property="key_uid"/>);'>确认全部</a>

     </logic:greaterThan>

     </logic:present>

     </td>

    </tr>

   </table>

  </td>

    </tr>

 <tr>

  <td align="center">

  <logic:present name="vcCpage">

  <html:pagetag pagename="vcCpage" hidFlag="true" conCode="top;pref;tpage;tnum;tocurpage;next;bottom;" title="首页;上一页;共;总计;第;下一页;末页;" conBlank="top;pref;tpage;tnum;tocurpage;next;bottom;" visible="false"/>

  </logic:present>

  </td>

  

 </tr>   

</center>

</body>

</html:html>

dwr.xml文件

web.xml文件

----------------------------------------------

<servlet>

 <servlet-name>dwr-invoker</servlet-name>

  <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>

</servlet>

<servlet-mapping>

  <servlet-name>dwr-invoker</servlet-name>

  <url-pattern>/dwr/*</url-pattern>

</servlet-mapping>

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=678192

  评论这张
 
阅读(109)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018