<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    置頂隨筆

    自己在公司網(wǎng)站開發(fā)總用DWR開發(fā)的一個簡單聊天
    本人也是在網(wǎng)站開發(fā)地圖時有到了這個技術(shù),剛學習DWR半個月
    就把隨手寫的一個簡單聊天來給大家共享,切磋一下。
    由于考慮到某些局部原因,只發(fā)表了一些重要技術(shù)方面的資料,沒有把全部東西共享。請個人體諒。
    由于DWR2.0有個Bug ,我用的DWR1.0,但是,它必須用JDK1.4
    dwr.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "<dwr>
    ? <init></init>
    ? <allow>
    ?<create creator="new" javascript="CityChatsend" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_send"/>
    ????? <include method="Chat_send"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatRead" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Read"/>
    ????? <include method="ChatRead"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatInit" scope="application">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Init"/>
    ????? <include method="getNew_Old"/>
    ?? <include method="setNew_Old"/>?
    ??? </create>

    ? </allow>
    </dwr>
    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;


    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    /**
    ?*Title? : 魅力城市聊天保存初始變量
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    ?
    public class DWRCityChar_Init
    {
    ?private static int now_ChatId=0;
    ?private static String InitSay="[公告^_^]:歡迎大家入住魅力城市^_^";
    ?private static String InitError="[公告^_^]:對不起!系統(tǒng)故障!我們會盡快解決!";
    ?private static String New_Old="0";
    ?public static String getInitError()
    ?{
    ??return InitError;
    ?}
    ?public static String getNew_Old()
    ?{
    ??return New_Old;
    ?}
    ?public static void setNew_Old()
    ?{
    ??New_Old="0";
    ?}
    ?public static synchronized void setInitSay(String Say)
    ?{
    ??InitSay=Say;
    ?}
    ?public static synchronized int getnow_ChatId()
    ?{
    ??if(now_ChatId==0)
    ??{
    ???int temp_ID=getRenow_ChatId();
    ???if(temp_ID>0)
    ???{
    ????setnow_ChatId(temp_ID);
    ???}else
    ???{
    ????startnewChat();?
    ???}
    ??}
    ??New_Old="1";//加載聊天記錄
    ??return now_ChatId;
    ?}
    ?public static synchronized void setnow_ChatId(int ChatId)
    ?{
    ??now_ChatId=ChatId;
    ?}
    ?public static synchronized void startnewChat()
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getinsertnewChat());
    ???? Date online=new Date();
    ?? ???? SimpleDateFormat fo=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ??????? String riqi=fo.format(online);
    ??????? prepare.setString(1,riqi);
    ??????? prepare.setString(2,InitSay);
    ??????? int result=prepare.executeUpdate();
    ??????? if(result>0)
    ??????? {
    ??????? ?setnow_ChatId(result);
    ??????? }
    ??????? else
    ??????? {
    ??????? ?startnewChat();
    ??????? }
    ??????? prepare.close();
    ??????? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ?}
    ?public static int getRenow_ChatId()
    ?{
    ?Connection conn=null;
    ??? PreparedStatement prepare=null;
    ??? ResultSet result=null;
    ??? int Return=0;
    ??? try
    ??? {
    ??? conn=DatabaseConnection.getConnection();
    ??? prepare=conn.prepareStatement(CityChart_InitSQL.getselectnewChatId());
    ??? result=prepare.executeQuery();
    ??? if(result.next())
    ??? {
    ??? ?Return=result.getInt("Id");
    ??? }
    ??? result.close();
    ??? prepare.close();
    ??? conn.close();
    ??? }catch(Exception we)
    ??? {
    ??? ?Return=-1;
    ??????? System.out.println(we.getMessage());
    ??? }finally
    ??? {
    ????????? try
    ??? ?{
    ??? ?if(!conn.isClosed())
    ??? ?{
    ??? ?prepare.close();
    ??? ?conn.close();
    ??? ?}?
    ??? ?}
    ??? ?catch(Exception ew)
    ??? ?{
    ??? ?}
    ??? }
    ??? return Return;?
    ?}
    }


    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    DWRCityChar_Read java文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    用到的JAVASCRIPT??? JS文件

    /**
    ?*Title? : 魅力城市聊天
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    var Send_state=0;//發(fā)送狀態(tài)
    var Chat_sendTime=500;
    var Chat_sendStart;
    var Chat_sendEnd;
    var Chat_sendstop;
    var Chat_result;
    var Chat_startWrite;
    var Chat_InitStart;
    var Chat_Readtime=500;
    function Chathotsend()
    {
    ?if(event.keyCode==10)
    ?{
    ??ChatSend();
    ?}
    }
    function getChat_Content()
    {
    ?var Content=null;
    ?var obj=document.getElementById('chat_input');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??Content=obj.value;
    ??if(Content!=null&&Content.length>400)
    ??{
    ???alert('對不起!你的聊天內(nèi)容過長,請你說話要簡練扼要!');
    ??}
    ?}else
    ?{
    ??Content=null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?return Content;
    }
    function ChatSend()
    {
    ?var UserName="";
    ?var obj=document.getElementById('Chat_User_name');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??UserName=obj.value;
    ?}else
    ?{
    ??UserName==null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ??return;
    ?}
    ?var Content=getChat_Content();
    ?if(Content==null||Content=='')
    ?{
    ??ShowAlert('請您輸入聊天內(nèi)容!');
    ??alert_time=setTimeout('ShowAlertCLose()',alert_showtime);
    ??alert('請您輸入聊天內(nèi)容!');
    ??return;
    ?}
    ?Chat_sendstop=setTimeout('ShowAlert()',Chat_sendTime);
    ?doChatSend(UserName,Content);
    ?var chatobj=document.getElementById('chat_input');
    ?chatobj.value='';
    ?chatobj.focus();
    ?
    ?
    }
    function doChatSend(UserName,Content)//聊天發(fā)送
    {
    ?Chat_sendStart=new Date();
    ?CityChatsend.Chat_send(UserName,Content,Chat_doResult);
    }
    function Chat_doResult(Return)//結(jié)果顯示
    {
    ?Send_state=Return;
    ?Chat_sendEnd=new Date();
    ?var temp=Chat_sendEnd-Chat_sendStart;
    ?if(temp>50)
    ?{
    ??Chat_sendTime=temp;
    ?}
    }
    function ShowAlert()
    {
    ?clearTimeout(Chat_sendstop);
    ?if(Send_state==-1)
    ?{
    ??alert('聊天提交時,出現(xiàn)數(shù)據(jù)庫插入異常!抱歉!請你重新輸入');
    ?}else if(Send_state==-2)
    ?{
    ??alert('對不起!聊天系統(tǒng)出現(xiàn)異常,給你帶來不便。在此,我代表AAA國際向你表示抱歉……');
    ?}
    }
    function ChatInit()
    {
    ?setInterval('ChatRead()',Chat_Readtime);
    }
    function ChatRead()
    {
    ?var chat_updiv=document.getElementById('chat_input_updiv');
    ?if(chat_updiv.style.display=='')
    ?{
    ?CityChatRead.ChatRead(getChatContent);
    ?Chat_startWrite=setTimeout('WriteChatContent()',1000);
    ?}
    }
    function WriteChatContent()
    {
    ?clearTimeout(Chat_startWrite);
    ?var obj=document.getElementById('chat_content');
    ?if(typeof(obj)=='object')
    ?{
    ?if(Chat_result!=null&&Chat_result!='')
    ?{
    ??obj.value=Chat_result;
    ?}else
    ?{
    ??obj.value='數(shù)據(jù)加載中......';
    ?}
    ?}else
    ?{
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?Chat_result=null;
    }
    function getChatContent(result)
    {
    ?Chat_result=result;
    }

    posted @ 2006-09-12 14:17 java^_^梟龍 閱讀(1299) | 評論 (0)編輯 收藏

    自己在公司網(wǎng)站開發(fā)總用DWR開發(fā)的一個簡單聊天
    本人也是在網(wǎng)站開發(fā)地圖時有到了這個技術(shù),剛學習DWR半個月
    就把隨手寫的一個簡單聊天來給大家共享,切磋一下。
    由于考慮到某些局部原因,只發(fā)表了一些重要技術(shù)方面的資料,沒有把全部東西共享。請個人體諒。
    由于DWR2.0有個Bug ,我用的DWR1.0,但是,它必須用JDK1.4
    dwr.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "<dwr>
    ? <init></init>
    ? <allow>
    ?<create creator="new" javascript="CityChatsend" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_send"/>
    ????? <include method="Chat_send"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatRead" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Read"/>
    ????? <include method="ChatRead"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatInit" scope="application">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Init"/>
    ????? <include method="getNew_Old"/>
    ?? <include method="setNew_Old"/>?
    ??? </create>

    ? </allow>
    </dwr>
    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;


    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    /**
    ?*Title? : 魅力城市聊天保存初始變量
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    ?
    public class DWRCityChar_Init
    {
    ?private static int now_ChatId=0;
    ?private static String InitSay="[公告^_^]:歡迎大家入住魅力城市^_^";
    ?private static String InitError="[公告^_^]:對不起!系統(tǒng)故障!我們會盡快解決!";
    ?private static String New_Old="0";
    ?public static String getInitError()
    ?{
    ??return InitError;
    ?}
    ?public static String getNew_Old()
    ?{
    ??return New_Old;
    ?}
    ?public static void setNew_Old()
    ?{
    ??New_Old="0";
    ?}
    ?public static synchronized void setInitSay(String Say)
    ?{
    ??InitSay=Say;
    ?}
    ?public static synchronized int getnow_ChatId()
    ?{
    ??if(now_ChatId==0)
    ??{
    ???int temp_ID=getRenow_ChatId();
    ???if(temp_ID>0)
    ???{
    ????setnow_ChatId(temp_ID);
    ???}else
    ???{
    ????startnewChat();?
    ???}
    ??}
    ??New_Old="1";//加載聊天記錄
    ??return now_ChatId;
    ?}
    ?public static synchronized void setnow_ChatId(int ChatId)
    ?{
    ??now_ChatId=ChatId;
    ?}
    ?public static synchronized void startnewChat()
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getinsertnewChat());
    ???? Date online=new Date();
    ?? ???? SimpleDateFormat fo=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ??????? String riqi=fo.format(online);
    ??????? prepare.setString(1,riqi);
    ??????? prepare.setString(2,InitSay);
    ??????? int result=prepare.executeUpdate();
    ??????? if(result>0)
    ??????? {
    ??????? ?setnow_ChatId(result);
    ??????? }
    ??????? else
    ??????? {
    ??????? ?startnewChat();
    ??????? }
    ??????? prepare.close();
    ??????? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ?}
    ?public static int getRenow_ChatId()
    ?{
    ?Connection conn=null;
    ??? PreparedStatement prepare=null;
    ??? ResultSet result=null;
    ??? int Return=0;
    ??? try
    ??? {
    ??? conn=DatabaseConnection.getConnection();
    ??? prepare=conn.prepareStatement(CityChart_InitSQL.getselectnewChatId());
    ??? result=prepare.executeQuery();
    ??? if(result.next())
    ??? {
    ??? ?Return=result.getInt("Id");
    ??? }
    ??? result.close();
    ??? prepare.close();
    ??? conn.close();
    ??? }catch(Exception we)
    ??? {
    ??? ?Return=-1;
    ??????? System.out.println(we.getMessage());
    ??? }finally
    ??? {
    ????????? try
    ??? ?{
    ??? ?if(!conn.isClosed())
    ??? ?{
    ??? ?prepare.close();
    ??? ?conn.close();
    ??? ?}?
    ??? ?}
    ??? ?catch(Exception ew)
    ??? ?{
    ??? ?}
    ??? }
    ??? return Return;?
    ?}
    }


    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    DWRCityChar_Read java文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    用到的JAVASCRIPT??? JS文件

    /**
    ?*Title? : 魅力城市聊天
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    var Send_state=0;//發(fā)送狀態(tài)
    var Chat_sendTime=500;
    var Chat_sendStart;
    var Chat_sendEnd;
    var Chat_sendstop;
    var Chat_result;
    var Chat_startWrite;
    var Chat_InitStart;
    var Chat_Readtime=500;
    function Chathotsend()
    {
    ?if(event.keyCode==10)
    ?{
    ??ChatSend();
    ?}
    }
    function getChat_Content()
    {
    ?var Content=null;
    ?var obj=document.getElementById('chat_input');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??Content=obj.value;
    ??if(Content!=null&&Content.length>400)
    ??{
    ???alert('對不起!你的聊天內(nèi)容過長,請你說話要簡練扼要!');
    ??}
    ?}else
    ?{
    ??Content=null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?return Content;
    }
    function ChatSend()
    {
    ?var UserName="";
    ?var obj=document.getElementById('Chat_User_name');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??UserName=obj.value;
    ?}else
    ?{
    ??UserName==null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ??return;
    ?}
    ?var Content=getChat_Content();
    ?if(Content==null||Content=='')
    ?{
    ??ShowAlert('請您輸入聊天內(nèi)容!');
    ??alert_time=setTimeout('ShowAlertCLose()',alert_showtime);
    ??alert('請您輸入聊天內(nèi)容!');
    ??return;
    ?}
    ?Chat_sendstop=setTimeout('ShowAlert()',Chat_sendTime);
    ?doChatSend(UserName,Content);
    ?var chatobj=document.getElementById('chat_input');
    ?chatobj.value='';
    ?chatobj.focus();
    ?
    ?
    }
    function doChatSend(UserName,Content)//聊天發(fā)送
    {
    ?Chat_sendStart=new Date();
    ?CityChatsend.Chat_send(UserName,Content,Chat_doResult);
    }
    function Chat_doResult(Return)//結(jié)果顯示
    {
    ?Send_state=Return;
    ?Chat_sendEnd=new Date();
    ?var temp=Chat_sendEnd-Chat_sendStart;
    ?if(temp>50)
    ?{
    ??Chat_sendTime=temp;
    ?}
    }
    function ShowAlert()
    {
    ?clearTimeout(Chat_sendstop);
    ?if(Send_state==-1)
    ?{
    ??alert('聊天提交時,出現(xiàn)數(shù)據(jù)庫插入異常!抱歉!請你重新輸入');
    ?}else if(Send_state==-2)
    ?{
    ??alert('對不起!聊天系統(tǒng)出現(xiàn)異常,給你帶來不便。在此,我代表AAA國際向你表示抱歉……');
    ?}
    }
    function ChatInit()
    {
    ?setInterval('ChatRead()',Chat_Readtime);
    }
    function ChatRead()
    {
    ?var chat_updiv=document.getElementById('chat_input_updiv');
    ?if(chat_updiv.style.display=='')
    ?{
    ?CityChatRead.ChatRead(getChatContent);
    ?Chat_startWrite=setTimeout('WriteChatContent()',1000);
    ?}
    }
    function WriteChatContent()
    {
    ?clearTimeout(Chat_startWrite);
    ?var obj=document.getElementById('chat_content');
    ?if(typeof(obj)=='object')
    ?{
    ?if(Chat_result!=null&&Chat_result!='')
    ?{
    ??obj.value=Chat_result;
    ?}else
    ?{
    ??obj.value='數(shù)據(jù)加載中......';
    ?}
    ?}else
    ?{
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?Chat_result=null;
    }
    function getChatContent(result)
    {
    ?Chat_result=result;
    }

    posted @ 2006-09-12 14:17 java^_^梟龍 閱讀(2164) | 評論 (1)編輯 收藏


    2006年9月12日

    自己在公司網(wǎng)站開發(fā)總用DWR開發(fā)的一個簡單聊天
    本人也是在網(wǎng)站開發(fā)地圖時有到了這個技術(shù),剛學習DWR半個月
    就把隨手寫的一個簡單聊天來給大家共享,切磋一下。
    由于考慮到某些局部原因,只發(fā)表了一些重要技術(shù)方面的資料,沒有把全部東西共享。請個人體諒。
    由于DWR2.0有個Bug ,我用的DWR1.0,但是,它必須用JDK1.4
    dwr.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "<dwr>
    ? <init></init>
    ? <allow>
    ?<create creator="new" javascript="CityChatsend" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_send"/>
    ????? <include method="Chat_send"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatRead" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Read"/>
    ????? <include method="ChatRead"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatInit" scope="application">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Init"/>
    ????? <include method="getNew_Old"/>
    ?? <include method="setNew_Old"/>?
    ??? </create>

    ? </allow>
    </dwr>
    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;


    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    /**
    ?*Title? : 魅力城市聊天保存初始變量
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    ?
    public class DWRCityChar_Init
    {
    ?private static int now_ChatId=0;
    ?private static String InitSay="[公告^_^]:歡迎大家入住魅力城市^_^";
    ?private static String InitError="[公告^_^]:對不起!系統(tǒng)故障!我們會盡快解決!";
    ?private static String New_Old="0";
    ?public static String getInitError()
    ?{
    ??return InitError;
    ?}
    ?public static String getNew_Old()
    ?{
    ??return New_Old;
    ?}
    ?public static void setNew_Old()
    ?{
    ??New_Old="0";
    ?}
    ?public static synchronized void setInitSay(String Say)
    ?{
    ??InitSay=Say;
    ?}
    ?public static synchronized int getnow_ChatId()
    ?{
    ??if(now_ChatId==0)
    ??{
    ???int temp_ID=getRenow_ChatId();
    ???if(temp_ID>0)
    ???{
    ????setnow_ChatId(temp_ID);
    ???}else
    ???{
    ????startnewChat();?
    ???}
    ??}
    ??New_Old="1";//加載聊天記錄
    ??return now_ChatId;
    ?}
    ?public static synchronized void setnow_ChatId(int ChatId)
    ?{
    ??now_ChatId=ChatId;
    ?}
    ?public static synchronized void startnewChat()
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getinsertnewChat());
    ???? Date online=new Date();
    ?? ???? SimpleDateFormat fo=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ??????? String riqi=fo.format(online);
    ??????? prepare.setString(1,riqi);
    ??????? prepare.setString(2,InitSay);
    ??????? int result=prepare.executeUpdate();
    ??????? if(result>0)
    ??????? {
    ??????? ?setnow_ChatId(result);
    ??????? }
    ??????? else
    ??????? {
    ??????? ?startnewChat();
    ??????? }
    ??????? prepare.close();
    ??????? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ?}
    ?public static int getRenow_ChatId()
    ?{
    ?Connection conn=null;
    ??? PreparedStatement prepare=null;
    ??? ResultSet result=null;
    ??? int Return=0;
    ??? try
    ??? {
    ??? conn=DatabaseConnection.getConnection();
    ??? prepare=conn.prepareStatement(CityChart_InitSQL.getselectnewChatId());
    ??? result=prepare.executeQuery();
    ??? if(result.next())
    ??? {
    ??? ?Return=result.getInt("Id");
    ??? }
    ??? result.close();
    ??? prepare.close();
    ??? conn.close();
    ??? }catch(Exception we)
    ??? {
    ??? ?Return=-1;
    ??????? System.out.println(we.getMessage());
    ??? }finally
    ??? {
    ????????? try
    ??? ?{
    ??? ?if(!conn.isClosed())
    ??? ?{
    ??? ?prepare.close();
    ??? ?conn.close();
    ??? ?}?
    ??? ?}
    ??? ?catch(Exception ew)
    ??? ?{
    ??? ?}
    ??? }
    ??? return Return;?
    ?}
    }


    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    DWRCityChar_Read java文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    用到的JAVASCRIPT??? JS文件

    /**
    ?*Title? : 魅力城市聊天
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    var Send_state=0;//發(fā)送狀態(tài)
    var Chat_sendTime=500;
    var Chat_sendStart;
    var Chat_sendEnd;
    var Chat_sendstop;
    var Chat_result;
    var Chat_startWrite;
    var Chat_InitStart;
    var Chat_Readtime=500;
    function Chathotsend()
    {
    ?if(event.keyCode==10)
    ?{
    ??ChatSend();
    ?}
    }
    function getChat_Content()
    {
    ?var Content=null;
    ?var obj=document.getElementById('chat_input');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??Content=obj.value;
    ??if(Content!=null&&Content.length>400)
    ??{
    ???alert('對不起!你的聊天內(nèi)容過長,請你說話要簡練扼要!');
    ??}
    ?}else
    ?{
    ??Content=null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?return Content;
    }
    function ChatSend()
    {
    ?var UserName="";
    ?var obj=document.getElementById('Chat_User_name');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??UserName=obj.value;
    ?}else
    ?{
    ??UserName==null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ??return;
    ?}
    ?var Content=getChat_Content();
    ?if(Content==null||Content=='')
    ?{
    ??ShowAlert('請您輸入聊天內(nèi)容!');
    ??alert_time=setTimeout('ShowAlertCLose()',alert_showtime);
    ??alert('請您輸入聊天內(nèi)容!');
    ??return;
    ?}
    ?Chat_sendstop=setTimeout('ShowAlert()',Chat_sendTime);
    ?doChatSend(UserName,Content);
    ?var chatobj=document.getElementById('chat_input');
    ?chatobj.value='';
    ?chatobj.focus();
    ?
    ?
    }
    function doChatSend(UserName,Content)//聊天發(fā)送
    {
    ?Chat_sendStart=new Date();
    ?CityChatsend.Chat_send(UserName,Content,Chat_doResult);
    }
    function Chat_doResult(Return)//結(jié)果顯示
    {
    ?Send_state=Return;
    ?Chat_sendEnd=new Date();
    ?var temp=Chat_sendEnd-Chat_sendStart;
    ?if(temp>50)
    ?{
    ??Chat_sendTime=temp;
    ?}
    }
    function ShowAlert()
    {
    ?clearTimeout(Chat_sendstop);
    ?if(Send_state==-1)
    ?{
    ??alert('聊天提交時,出現(xiàn)數(shù)據(jù)庫插入異常!抱歉!請你重新輸入');
    ?}else if(Send_state==-2)
    ?{
    ??alert('對不起!聊天系統(tǒng)出現(xiàn)異常,給你帶來不便。在此,我代表AAA國際向你表示抱歉……');
    ?}
    }
    function ChatInit()
    {
    ?setInterval('ChatRead()',Chat_Readtime);
    }
    function ChatRead()
    {
    ?var chat_updiv=document.getElementById('chat_input_updiv');
    ?if(chat_updiv.style.display=='')
    ?{
    ?CityChatRead.ChatRead(getChatContent);
    ?Chat_startWrite=setTimeout('WriteChatContent()',1000);
    ?}
    }
    function WriteChatContent()
    {
    ?clearTimeout(Chat_startWrite);
    ?var obj=document.getElementById('chat_content');
    ?if(typeof(obj)=='object')
    ?{
    ?if(Chat_result!=null&&Chat_result!='')
    ?{
    ??obj.value=Chat_result;
    ?}else
    ?{
    ??obj.value='數(shù)據(jù)加載中......';
    ?}
    ?}else
    ?{
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?Chat_result=null;
    }
    function getChatContent(result)
    {
    ?Chat_result=result;
    }

    posted @ 2006-09-12 14:17 java^_^梟龍 閱讀(1299) | 評論 (0)編輯 收藏

    自己在公司網(wǎng)站開發(fā)總用DWR開發(fā)的一個簡單聊天
    本人也是在網(wǎng)站開發(fā)地圖時有到了這個技術(shù),剛學習DWR半個月
    就把隨手寫的一個簡單聊天來給大家共享,切磋一下。
    由于考慮到某些局部原因,只發(fā)表了一些重要技術(shù)方面的資料,沒有把全部東西共享。請個人體諒。
    由于DWR2.0有個Bug ,我用的DWR1.0,但是,它必須用JDK1.4
    dwr.xml文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "<dwr>
    ? <init></init>
    ? <allow>
    ?<create creator="new" javascript="CityChatsend" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_send"/>
    ????? <include method="Chat_send"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatRead" scope="session">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Read"/>
    ????? <include method="ChatRead"/>?
    ??? </create>
    ?<create creator="new" javascript="CityChatInit" scope="application">
    ????? <param name="class" value="com.aaa.CharChat.DWR.DWRCityChar_Init"/>
    ????? <include method="getNew_Old"/>
    ?? <include method="setNew_Old"/>?
    ??? </create>

    ? </allow>
    </dwr>
    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;


    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;
    import java.util.Date;
    import java.text.SimpleDateFormat;
    /**
    ?*Title? : 魅力城市聊天保存初始變量
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    ?
    public class DWRCityChar_Init
    {
    ?private static int now_ChatId=0;
    ?private static String InitSay="[公告^_^]:歡迎大家入住魅力城市^_^";
    ?private static String InitError="[公告^_^]:對不起!系統(tǒng)故障!我們會盡快解決!";
    ?private static String New_Old="0";
    ?public static String getInitError()
    ?{
    ??return InitError;
    ?}
    ?public static String getNew_Old()
    ?{
    ??return New_Old;
    ?}
    ?public static void setNew_Old()
    ?{
    ??New_Old="0";
    ?}
    ?public static synchronized void setInitSay(String Say)
    ?{
    ??InitSay=Say;
    ?}
    ?public static synchronized int getnow_ChatId()
    ?{
    ??if(now_ChatId==0)
    ??{
    ???int temp_ID=getRenow_ChatId();
    ???if(temp_ID>0)
    ???{
    ????setnow_ChatId(temp_ID);
    ???}else
    ???{
    ????startnewChat();?
    ???}
    ??}
    ??New_Old="1";//加載聊天記錄
    ??return now_ChatId;
    ?}
    ?public static synchronized void setnow_ChatId(int ChatId)
    ?{
    ??now_ChatId=ChatId;
    ?}
    ?public static synchronized void startnewChat()
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getinsertnewChat());
    ???? Date online=new Date();
    ?? ???? SimpleDateFormat fo=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ??????? String riqi=fo.format(online);
    ??????? prepare.setString(1,riqi);
    ??????? prepare.setString(2,InitSay);
    ??????? int result=prepare.executeUpdate();
    ??????? if(result>0)
    ??????? {
    ??????? ?setnow_ChatId(result);
    ??????? }
    ??????? else
    ??????? {
    ??????? ?startnewChat();
    ??????? }
    ??????? prepare.close();
    ??????? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ?}
    ?public static int getRenow_ChatId()
    ?{
    ?Connection conn=null;
    ??? PreparedStatement prepare=null;
    ??? ResultSet result=null;
    ??? int Return=0;
    ??? try
    ??? {
    ??? conn=DatabaseConnection.getConnection();
    ??? prepare=conn.prepareStatement(CityChart_InitSQL.getselectnewChatId());
    ??? result=prepare.executeQuery();
    ??? if(result.next())
    ??? {
    ??? ?Return=result.getInt("Id");
    ??? }
    ??? result.close();
    ??? prepare.close();
    ??? conn.close();
    ??? }catch(Exception we)
    ??? {
    ??? ?Return=-1;
    ??????? System.out.println(we.getMessage());
    ??? }finally
    ??? {
    ????????? try
    ??? ?{
    ??? ?if(!conn.isClosed())
    ??? ?{
    ??? ?prepare.close();
    ??? ?conn.close();
    ??? ?}?
    ??? ?}
    ??? ?catch(Exception ew)
    ??? ?{
    ??? ?}
    ??? }
    ??? return Return;?
    ?}
    }


    DWRCityChar_send JAVA文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    DWRCityChar_Read java文件
    package com.aaa.CharChat.DWR;

    import java.sql.*;
    import java.util.*;
    import com.db.DatabaseConnection;
    import com.aaa.CharChat.DWR.DWRCityChar_Init;
    import com.aaa.CharChat.initSQL.CityChart_InitSQL;

    /**
    ?*Title? : 魅力城市聊天發(fā)送
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-9-9
    ?**/
    public class DWRCityChar_send
    {
    ?public int Chat_send(String User_name,String Content)
    ?{
    ??int Return=0;
    ??try
    ??{
    ??String result="["+User_name+"]說:"+Content;
    ??int nowId=DWRCityChar_Init.getnow_ChatId();
    ??
    ??if(nowId>0)
    ??{
    ???Return=dosend(nowId,result);
    ??}else
    ??{
    ???Return=-2;
    ??}
    ??}catch(Exception we)
    ??{
    ???
    ??}
    ??return Return;
    ?}
    ?public int dosend(int nowId,String result)
    ?{
    ??Connection conn=null;
    ???? PreparedStatement prepare=null;
    ???? PreparedStatement prepare1=null;
    ???? ResultSet resu=null;
    ???? String Content="";
    ???? int Return=0;
    ???? try
    ???? {
    ???? conn=DatabaseConnection.getConnection();
    ???? prepare=conn.prepareStatement(CityChart_InitSQL.getselectChatbyId());
    ???? prepare1=conn.prepareStatement(CityChart_InitSQL.getupdateChatbyId());
    ???? prepare.setInt(1,nowId);
    ???? resu=prepare.executeQuery();
    ???? if(resu.next())
    ???? {
    ???? ?Content=resu.getString("Content");
    ???? }
    ???? resu.close();
    ???? prepare.close();
    ???? if(Content.length()>4000)
    ???? {
    ???? DWRCityChar_Init.startnewChat();
    ???? nowId=DWRCityChar_Init.getnow_ChatId();?
    ???? }
    ???? Content=result+"\n"+Content;
    ???? prepare1.setString(1,Content);
    ???? prepare1.setInt(2,nowId);
    ???? Return=prepare1.executeUpdate();
    ???? prepare1.close();
    ???? conn.close();
    ???? }catch(Exception we)
    ???? {
    ???? ?Return=-1;
    ???????? System.out.println(we.getMessage());
    ???? }finally
    ???? {
    ?????????? try
    ???? ?{
    ???? ?if(!conn.isClosed())
    ???? ?{
    ???? ?prepare.close();
    ???? ?prepare1.close();
    ???? ?conn.close();
    ???? ?}?
    ???? ?}
    ???? ?catch(Exception ew)
    ???? ?{
    ???? ?}
    ???? }
    ???? return Return;
    ?}
    }

    用到的JAVASCRIPT??? JS文件

    /**
    ?*Title? : 魅力城市聊天
    ?*Author : JAVA^_^梟龍---孫德華
    ?*Project: 數(shù)字城市
    ?*Date?? : 2006-09-9
    ?**/
    var Send_state=0;//發(fā)送狀態(tài)
    var Chat_sendTime=500;
    var Chat_sendStart;
    var Chat_sendEnd;
    var Chat_sendstop;
    var Chat_result;
    var Chat_startWrite;
    var Chat_InitStart;
    var Chat_Readtime=500;
    function Chathotsend()
    {
    ?if(event.keyCode==10)
    ?{
    ??ChatSend();
    ?}
    }
    function getChat_Content()
    {
    ?var Content=null;
    ?var obj=document.getElementById('chat_input');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??Content=obj.value;
    ??if(Content!=null&&Content.length>400)
    ??{
    ???alert('對不起!你的聊天內(nèi)容過長,請你說話要簡練扼要!');
    ??}
    ?}else
    ?{
    ??Content=null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?return Content;
    }
    function ChatSend()
    {
    ?var UserName="";
    ?var obj=document.getElementById('Chat_User_name');//獲取聊天內(nèi)容
    ?if(typeof(obj)=='object')
    ?{
    ??UserName=obj.value;
    ?}else
    ?{
    ??UserName==null;
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ??return;
    ?}
    ?var Content=getChat_Content();
    ?if(Content==null||Content=='')
    ?{
    ??ShowAlert('請您輸入聊天內(nèi)容!');
    ??alert_time=setTimeout('ShowAlertCLose()',alert_showtime);
    ??alert('請您輸入聊天內(nèi)容!');
    ??return;
    ?}
    ?Chat_sendstop=setTimeout('ShowAlert()',Chat_sendTime);
    ?doChatSend(UserName,Content);
    ?var chatobj=document.getElementById('chat_input');
    ?chatobj.value='';
    ?chatobj.focus();
    ?
    ?
    }
    function doChatSend(UserName,Content)//聊天發(fā)送
    {
    ?Chat_sendStart=new Date();
    ?CityChatsend.Chat_send(UserName,Content,Chat_doResult);
    }
    function Chat_doResult(Return)//結(jié)果顯示
    {
    ?Send_state=Return;
    ?Chat_sendEnd=new Date();
    ?var temp=Chat_sendEnd-Chat_sendStart;
    ?if(temp>50)
    ?{
    ??Chat_sendTime=temp;
    ?}
    }
    function ShowAlert()
    {
    ?clearTimeout(Chat_sendstop);
    ?if(Send_state==-1)
    ?{
    ??alert('聊天提交時,出現(xiàn)數(shù)據(jù)庫插入異常!抱歉!請你重新輸入');
    ?}else if(Send_state==-2)
    ?{
    ??alert('對不起!聊天系統(tǒng)出現(xiàn)異常,給你帶來不便。在此,我代表AAA國際向你表示抱歉……');
    ?}
    }
    function ChatInit()
    {
    ?setInterval('ChatRead()',Chat_Readtime);
    }
    function ChatRead()
    {
    ?var chat_updiv=document.getElementById('chat_input_updiv');
    ?if(chat_updiv.style.display=='')
    ?{
    ?CityChatRead.ChatRead(getChatContent);
    ?Chat_startWrite=setTimeout('WriteChatContent()',1000);
    ?}
    }
    function WriteChatContent()
    {
    ?clearTimeout(Chat_startWrite);
    ?var obj=document.getElementById('chat_content');
    ?if(typeof(obj)=='object')
    ?{
    ?if(Chat_result!=null&&Chat_result!='')
    ?{
    ??obj.value=Chat_result;
    ?}else
    ?{
    ??obj.value='數(shù)據(jù)加載中......';
    ?}
    ?}else
    ?{
    ??alert('程序內(nèi)部出現(xiàn)異常,抱歉!我們會盡快解決');
    ?}
    ?Chat_result=null;
    }
    function getChatContent(result)
    {
    ?Chat_result=result;
    }

    posted @ 2006-09-12 14:17 java^_^梟龍 閱讀(2164) | 評論 (1)編輯 收藏


    僅列出標題  

    posts - 2, comments - 1, trackbacks - 0, articles - 0

    Copyright © java^_^梟龍

    主站蜘蛛池模板: 日韩一区二区在线免费观看 | 亚洲欧洲免费视频| 亚洲AV日韩精品一区二区三区| 亚洲一日韩欧美中文字幕在线| 日本免费xxxx色视频| 亚洲国产午夜精品理论片| 久草视频免费在线| 日韩精品亚洲人成在线观看| 中文字幕天天躁日日躁狠狠躁免费| 亚洲V无码一区二区三区四区观看| 精品一区二区三区免费| 亚洲成在人天堂一区二区| 69av免费观看| 亚洲最大无码中文字幕| 国产午夜影视大全免费观看| 暖暖免费中文在线日本| 亚洲精品无码午夜福利中文字幕| 中文字幕在线视频免费| 亚洲视频网站在线观看| 性色av免费观看| 色哟哟国产精品免费观看| 亚洲精品无码久久久久sm| 免费不卡在线观看AV| 亚洲午夜福利在线视频| 亚洲国产天堂久久久久久| 国色精品va在线观看免费视频| 久久国产亚洲高清观看| 成人免费a级毛片无码网站入口| 美女被免费网站视频在线| 亚洲日韩中文字幕在线播放| 国产精品久久免费| 蜜臀亚洲AV无码精品国产午夜.| 亚洲综合色成在线播放| 亚州免费一级毛片| 午夜在线亚洲男人午在线| 日韩亚洲欧洲在线com91tv| 91九色精品国产免费| 日韩精品无码免费视频| 亚洲网红精品大秀在线观看| 国产一级特黄高清免费大片| 无码人妻一区二区三区免费n鬼沢|