`
niatwangcong
  • 浏览: 86452 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论
阅读更多
 <wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">
23</wbr><wbr style="LINE-HEIGHT: 1.3em">
24</wbr><wbr style="LINE-HEIGHT: 1.3em">
25</wbr><wbr style="LINE-HEIGHT: 1.3em">
26</wbr><wbr style="LINE-HEIGHT: 1.3em">
27</wbr><wbr style="LINE-HEIGHT: 1.3em">
28</wbr><wbr style="LINE-HEIGHT: 1.3em">
29</wbr><wbr style="LINE-HEIGHT: 1.3em">
30</wbr><wbr style="LINE-HEIGHT: 1.3em">
31</wbr><wbr style="LINE-HEIGHT: 1.3em">
32</wbr><wbr style="LINE-HEIGHT: 1.3em">
33</wbr><wbr style="LINE-HEIGHT: 1.3em">
34</wbr><wbr style="LINE-HEIGHT: 1.3em">
35</wbr><wbr style="LINE-HEIGHT: 1.3em">
36</wbr><wbr style="LINE-HEIGHT: 1.3em">
37</wbr><wbr style="LINE-HEIGHT: 1.3em">
38</wbr><wbr style="LINE-HEIGHT: 1.3em">
39</wbr><wbr style="LINE-HEIGHT: 1.3em">
40</wbr><wbr style="LINE-HEIGHT: 1.3em">
41</wbr><wbr style="LINE-HEIGHT: 1.3em">
42</wbr><wbr style="LINE-HEIGHT: 1.3em">
43</wbr><wbr style="LINE-HEIGHT: 1.3em">
44</wbr><wbr style="LINE-HEIGHT: 1.3em">
45</wbr><wbr style="LINE-HEIGHT: 1.3em">
46</wbr><wbr style="LINE-HEIGHT: 1.3em">
47</wbr><wbr style="LINE-HEIGHT: 1.3em">
48</wbr><wbr style="LINE-HEIGHT: 1.3em">
49</wbr><wbr style="LINE-HEIGHT: 1.3em">
50</wbr><wbr style="LINE-HEIGHT: 1.3em">
51</wbr><wbr style="LINE-HEIGHT: 1.3em">
52</wbr><wbr style="LINE-HEIGHT: 1.3em">
53</wbr><wbr style="LINE-HEIGHT: 1.3em">
54</wbr><wbr style="LINE-HEIGHT: 1.3em">
55</wbr><wbr style="LINE-HEIGHT: 1.3em">

<wbr>package</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> onlyfun.caterpillar;

<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.io.IOException;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.io.PrintWriter;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.util.LinkedList;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.util.List;

<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> javax.servlet.ServletException;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> javax.servlet.http.HttpServletRequest;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> javax.servlet.http.HttpServletResponse;

<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>class</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ChatRoomServlet <wbr>extends</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> javax.servlet.http.HttpServlet <wbr>implements</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> javax.servlet.Servlet {</wbr><wbr style="LINE-HEIGHT: 1.3em">
     <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>static</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> LinkedList<Message> messages = <wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> LinkedList<Message>();
    
     <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ChatRoomServlet() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>super</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">();
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">
    
    <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> List<Message> addMessage(String text) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (text != <wbr>null</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> && text.trim().length() > 0) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
            messages.addFirst(<wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Message(text));
            <wbr>while</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (messages.size() > 10) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
                messages.removeLast();
            }</wbr><wbr style="LINE-HEIGHT: 1.3em">
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">

        <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> messages;
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">

    <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> List<Message> getMessages() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> messages;
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">
    
  <wbr>protected</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>void</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> doPost(HttpServletRequest request, HttpServletResponse response) <wbr>throws</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ServletException, IOException {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        List<Message> list = <wbr>null</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">;
        
        <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">("send"</wbr><wbr style="LINE-HEIGHT: 1.3em">.equals(request.getParameter("task"</wbr><wbr style="LINE-HEIGHT: 1.3em">))) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
             list = addMessage(request.getParameter("msg"</wbr><wbr style="LINE-HEIGHT: 1.3em">));
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>else</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">("query"</wbr><wbr style="LINE-HEIGHT: 1.3em">.equals(request.getParameter("task"</wbr><wbr style="LINE-HEIGHT: 1.3em">))){</wbr><wbr style="LINE-HEIGHT: 1.3em">
             list = getMessages();
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">

        PrintWriter out = response.getWriter();
        response.setContentType("text/xml"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
        response.setHeader("Cache-Control"</wbr><wbr style="LINE-HEIGHT: 1.3em">, "no-cache"</wbr><wbr style="LINE-HEIGHT: 1.3em">);

        out.println("<response>"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
        <wbr>for</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">(<wbr>int</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> i = 0; i < list.size(); i++) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
            String msg = list.get(i).getText();
            out.println("<message>"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + msg + "</message>"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">
        out.println("</response>"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">            
}</wbr><wbr style="LINE-HEIGHT: 1.3em">


Message物件如下…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">
23</wbr><wbr style="LINE-HEIGHT: 1.3em">

<wbr>package</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> onlyfun.caterpillar;

<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>class</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Message {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>long</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> id = System.currentTimeMillis();
    <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> String text;
    
    <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Message(String newtext) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        text = newtext;
        <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (text.length() > 256) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
            text = text.substring(0, 256);
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">
        text = text.replace('<'</wbr><wbr style="LINE-HEIGHT: 1.3em">, '['</wbr><wbr style="LINE-HEIGHT: 1.3em">);
        text = text.replace('&'</wbr><wbr style="LINE-HEIGHT: 1.3em">, '_'</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">

    <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>long</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> getId() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> id;
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">

    <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> String getText() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> text;
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">


Servlet接受訊息新增與查詢,判斷的方式是檢查請求參數task是send或query。

Servlet會以XML傳回目前List當中的訊息,客戶端可以查詢或插入新訊息時,取得目前List中的訊息,接著在web.xml中設定一下…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">

<?xml version="1.0"</wbr><wbr style="LINE-HEIGHT: 1.3em"> encoding="UTF-8"</wbr><wbr style="LINE-HEIGHT: 1.3em">?>
<web-app id="WebApp_ID"</wbr><wbr style="LINE-HEIGHT: 1.3em"> version="2.4"</wbr><wbr style="LINE-HEIGHT: 1.3em"> xmlns="http://java.sun.com/xml/ns/j2ee"</wbr><wbr style="LINE-HEIGHT: 1.3em"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</wbr><wbr style="LINE-HEIGHT: 1.3em"> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
  <servlet>
    <description>
    </description>
    <display-name>
    ChatRoomServlet</display-name>
    <servlet-name>ChatRoomServlet</servlet-name>
    <servlet-class>
    onlyfun.caterpillar.ChatRoomServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>ChatRoomServlet</servlet-name>
    <url-pattern>/ChatRoomServlet</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>
            30
        </session-timeout>
  </session-config>  
</web-app>



在網頁中,使用者可以在輸入訊息後按下按鈕送出資訊,並在XML回應取得時,將訊息以一列一列的表格方式顯示出來,另外還設定了週期性的輪詢,即使不輸入新訊息,也可以週期性的取得新的聊天訊息…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">
23</wbr><wbr style="LINE-HEIGHT: 1.3em">
24</wbr><wbr style="LINE-HEIGHT: 1.3em">
25</wbr><wbr style="LINE-HEIGHT: 1.3em">
26</wbr><wbr style="LINE-HEIGHT: 1.3em">
27</wbr><wbr style="LINE-HEIGHT: 1.3em">
28</wbr><wbr style="LINE-HEIGHT: 1.3em">
29</wbr><wbr style="LINE-HEIGHT: 1.3em">
30</wbr><wbr style="LINE-HEIGHT: 1.3em">
31</wbr><wbr style="LINE-HEIGHT: 1.3em">
32</wbr><wbr style="LINE-HEIGHT: 1.3em">
33</wbr><wbr style="LINE-HEIGHT: 1.3em">
34</wbr><wbr style="LINE-HEIGHT: 1.3em">
35</wbr><wbr style="LINE-HEIGHT: 1.3em">
36</wbr><wbr style="LINE-HEIGHT: 1.3em">
37</wbr><wbr style="LINE-HEIGHT: 1.3em">
38</wbr><wbr style="LINE-HEIGHT: 1.3em">
39</wbr><wbr style="LINE-HEIGHT: 1.3em">
40</wbr><wbr style="LINE-HEIGHT: 1.3em">
41</wbr><wbr style="LINE-HEIGHT: 1.3em">
42</wbr><wbr style="LINE-HEIGHT: 1.3em">
43</wbr><wbr style="LINE-HEIGHT: 1.3em">
44</wbr><wbr style="LINE-HEIGHT: 1.3em">
45</wbr><wbr style="LINE-HEIGHT: 1.3em">
46</wbr><wbr style="LINE-HEIGHT: 1.3em">
47</wbr><wbr style="LINE-HEIGHT: 1.3em">
48</wbr><wbr style="LINE-HEIGHT: 1.3em">
49</wbr><wbr style="LINE-HEIGHT: 1.3em">
50</wbr><wbr style="LINE-HEIGHT: 1.3em">
51</wbr><wbr style="LINE-HEIGHT: 1.3em">
52</wbr><wbr style="LINE-HEIGHT: 1.3em">
53</wbr><wbr style="LINE-HEIGHT: 1.3em">
54</wbr><wbr style="LINE-HEIGHT: 1.3em">
55</wbr><wbr style="LINE-HEIGHT: 1.3em">
56</wbr><wbr style="LINE-HEIGHT: 1.3em">
57</wbr><wbr style="LINE-HEIGHT: 1.3em">
58</wbr><wbr style="LINE-HEIGHT: 1.3em">
59</wbr><wbr style="LINE-HEIGHT: 1.3em">
60</wbr><wbr style="LINE-HEIGHT: 1.3em">
61</wbr><wbr style="LINE-HEIGHT: 1.3em">
62</wbr><wbr style="LINE-HEIGHT: 1.3em">
63</wbr><wbr style="LINE-HEIGHT: 1.3em">
64</wbr><wbr style="LINE-HEIGHT: 1.3em">
65</wbr><wbr style="LINE-HEIGHT: 1.3em">
66</wbr><wbr style="LINE-HEIGHT: 1.3em">
67</wbr><wbr style="LINE-HEIGHT: 1.3em">
68</wbr><wbr style="LINE-HEIGHT: 1.3em">
69</wbr><wbr style="LINE-HEIGHT: 1.3em">
70</wbr><wbr style="LINE-HEIGHT: 1.3em">
71</wbr><wbr style="LINE-HEIGHT: 1.3em">
72</wbr><wbr style="LINE-HEIGHT: 1.3em">
73</wbr><wbr style="LINE-HEIGHT: 1.3em">
74</wbr><wbr style="LINE-HEIGHT: 1.3em">
75</wbr><wbr style="LINE-HEIGHT: 1.3em">
76</wbr><wbr style="LINE-HEIGHT: 1.3em">
77</wbr><wbr style="LINE-HEIGHT: 1.3em">
78</wbr><wbr style="LINE-HEIGHT: 1.3em">
79</wbr><wbr style="LINE-HEIGHT: 1.3em">
80</wbr><wbr style="LINE-HEIGHT: 1.3em">
81</wbr><wbr style="LINE-HEIGHT: 1.3em">
82</wbr><wbr style="LINE-HEIGHT: 1.3em">
83</wbr><wbr style="LINE-HEIGHT: 1.3em">
84</wbr><wbr style="LINE-HEIGHT: 1.3em">
85</wbr><wbr style="LINE-HEIGHT: 1.3em">
86</wbr><wbr style="LINE-HEIGHT: 1.3em">
87</wbr><wbr style="LINE-HEIGHT: 1.3em">
88</wbr><wbr style="LINE-HEIGHT: 1.3em">
89</wbr><wbr style="LINE-HEIGHT: 1.3em">
90</wbr><wbr style="LINE-HEIGHT: 1.3em">
91</wbr><wbr style="LINE-HEIGHT: 1.3em">
92</wbr><wbr style="LINE-HEIGHT: 1.3em">
93</wbr><wbr style="LINE-HEIGHT: 1.3em">
94</wbr><wbr style="LINE-HEIGHT: 1.3em">
95</wbr><wbr style="LINE-HEIGHT: 1.3em">
96</wbr><wbr style="LINE-HEIGHT: 1.3em">
97</wbr><wbr style="LINE-HEIGHT: 1.3em">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<html>
<head>
<meta http-equiv="Content-Type"</wbr><wbr style="LINE-HEIGHT: 1.3em"> content="text/html; charset=BIG5"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<title>Chat Room</title>

<script type="text/javascript"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
var xmlHttp;

function createXMLHttpRequest() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (window.ActiveXObject) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        xmlHttp = <wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ActiveXObject("Microsoft.XMLHTTP"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>else</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (window.XMLHttpRequest) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        xmlHttp = <wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> XMLHttpRequest();
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function sendMessage() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  var msg = document.getElementById("text"</wbr><wbr style="LINE-HEIGHT: 1.3em">).value;
  
  <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">(msg == ""</wbr><wbr style="LINE-HEIGHT: 1.3em">) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    refreshMessage();
    <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">;
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">
  
  var param = "task=send&msg="</wbr><wbr style="LINE-HEIGHT: 1.3em"> + msg;
  ajaxRequest(param);
  document.getElementById("text"</wbr><wbr style="LINE-HEIGHT: 1.3em">).value = ""</wbr><wbr style="LINE-HEIGHT: 1.3em">;
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function queryMessage() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  var param = "task=query"</wbr><wbr style="LINE-HEIGHT: 1.3em">;
  ajaxRequest(param);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function ajaxRequest(param) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  var url = "ChatRoomServlet?timestamp"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + <wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Date().getTime();
    createXMLHttpRequest();
  xmlHttp.onreadystatechange = refreshMessage;
    xmlHttp.open("POST"</wbr><wbr style="LINE-HEIGHT: 1.3em">, url, <wbr>true</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">);
  xmlHttp.setRequestHeader("Content-Type"</wbr><wbr style="LINE-HEIGHT: 1.3em">,
           "application/x-www-form-urlencoded;"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    xmlHttp.send(param);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
  
function refreshMessage() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">(xmlHttp.readyState == 4) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">(xmlHttp.status == 200) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
          var messages = xmlHttp.responseXML.getElementsByTagName("message"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
  
          var table_body = document.getElementById("dynamicUpdateArea"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
      var length = table_body.childNodes.length;
      <wbr>for</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (var i = 0; i < length; i++) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        table_body.removeChild(table_body.childNodes[0]);
      }</wbr><wbr style="LINE-HEIGHT: 1.3em">
      
      var length = messages.length;
          <wbr>for</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em">(var i = length - 1; i >= 0 ; i--) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
              var message = messages[i].firstChild.data;
              var row = createRow(message);
        
              table_body.appendChild(row);                        
          }</wbr><wbr style="LINE-HEIGHT: 1.3em">
      setTimeout("queryMessage()"</wbr><wbr style="LINE-HEIGHT: 1.3em">, 2000);
        }</wbr><wbr style="LINE-HEIGHT: 1.3em">
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function createRow(message) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    var row = document.createElement("tr"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    var cell = document.createElement("td"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    var cell_data = document.createTextNode(message);
    cell.appendChild(cell_data);
    row.appendChild(cell);
    <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> row;
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

</script>

</head>
<body>

<p>
  Your Message:
  <input id="text"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
  <input type="button"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="Send"</wbr><wbr style="LINE-HEIGHT: 1.3em">
      onclick="sendMessage()"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
</p>

<p>Messages:</p>
    <table align="left"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
        <tbody id="dynamicUpdateArea"</wbr><wbr style="LINE-HEIGHT: 1.3em">></tbody>
    </table>

</body>
</html>



簡單抓個畫面…  
</wbr><wbr></wbr><wbr>

直接用AJAX,後端用JSP/Servlet,您要對請求參數做些判斷,看看是新增訊息或查詢,並要自行輸出XML,有的沒的…

改成DWR的話,就很簡單了,寫個簡單的Java物件…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">
23</wbr><wbr style="LINE-HEIGHT: 1.3em">

<wbr>package</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> onlyfun.caterpillar;

<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.util.LinkedList;
<wbr>import</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> java.util.List;

<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>class</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Chat {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  <wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>static</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> LinkedList<Message> messages = <wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> LinkedList<Message>();

  <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> List addMessage(String text) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>if</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (text != <wbr>null</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> && text.trim().length() > 0) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
      messages.addFirst(<wbr>new</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Message(text));
      <wbr>while</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (messages.size() > 10) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        messages.removeLast();
      }</wbr><wbr style="LINE-HEIGHT: 1.3em">
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">

    <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> messages;
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">

  <wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> List getMessages() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    <wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> messages;
  }</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">


接著…在dwr.xml中開放一下…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">

<?xml version="1.0"</wbr><wbr style="LINE-HEIGHT: 1.3em"> encoding="UTF-8"</wbr><wbr style="LINE-HEIGHT: 1.3em">?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"</wbr><wbr style="LINE-HEIGHT: 1.3em"> "http://www.getahead.ltd.uk/dwr/dwr10.dtd"</wbr><wbr style="LINE-HEIGHT: 1.3em">>

<dwr>
  <allow>

    <create creator="new"</wbr><wbr style="LINE-HEIGHT: 1.3em"> javascript="Chat"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
      <param name="class"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="onlyfun.caterpillar.Chat"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
    </create>
    
    <convert converter="bean"</wbr><wbr style="LINE-HEIGHT: 1.3em"> match="onlyfun.caterpillar.Message"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>      
  </allow>
</dwr>



使用者取得訊息時,是直接傳回List物件,而List中裝的是Message物件,Message物件是自訂物件,conterver設定為 bean,表示DWR會自動將Message的getter名稱轉換為傳回客戶端的JavaScript物件中的屬性,例如Message中有 getText(),則在客戶端可以用message.text這樣的方式來存取。

接著是簡單的客戶端網頁…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
4</wbr><wbr style="LINE-HEIGHT: 1.3em">
5</wbr><wbr style="LINE-HEIGHT: 1.3em">
6</wbr><wbr style="LINE-HEIGHT: 1.3em">
7</wbr><wbr style="LINE-HEIGHT: 1.3em">
8</wbr><wbr style="LINE-HEIGHT: 1.3em">
9</wbr><wbr style="LINE-HEIGHT: 1.3em">
10</wbr><wbr style="LINE-HEIGHT: 1.3em">
11</wbr><wbr style="LINE-HEIGHT: 1.3em">
12</wbr><wbr style="LINE-HEIGHT: 1.3em">
13</wbr><wbr style="LINE-HEIGHT: 1.3em">
14</wbr><wbr style="LINE-HEIGHT: 1.3em">
15</wbr><wbr style="LINE-HEIGHT: 1.3em">
16</wbr><wbr style="LINE-HEIGHT: 1.3em">
17</wbr><wbr style="LINE-HEIGHT: 1.3em">
18</wbr><wbr style="LINE-HEIGHT: 1.3em">
19</wbr><wbr style="LINE-HEIGHT: 1.3em">
20</wbr><wbr style="LINE-HEIGHT: 1.3em">
21</wbr><wbr style="LINE-HEIGHT: 1.3em">
22</wbr><wbr style="LINE-HEIGHT: 1.3em">
23</wbr><wbr style="LINE-HEIGHT: 1.3em">
24</wbr><wbr style="LINE-HEIGHT: 1.3em">
25</wbr><wbr style="LINE-HEIGHT: 1.3em">
26</wbr><wbr style="LINE-HEIGHT: 1.3em">
27</wbr><wbr style="LINE-HEIGHT: 1.3em">
28</wbr><wbr style="LINE-HEIGHT: 1.3em">
29</wbr><wbr style="LINE-HEIGHT: 1.3em">
30</wbr><wbr style="LINE-HEIGHT: 1.3em">
31</wbr><wbr style="LINE-HEIGHT: 1.3em">
32</wbr><wbr style="LINE-HEIGHT: 1.3em">
33</wbr><wbr style="LINE-HEIGHT: 1.3em">
34</wbr><wbr style="LINE-HEIGHT: 1.3em">
35</wbr><wbr style="LINE-HEIGHT: 1.3em">
36</wbr><wbr style="LINE-HEIGHT: 1.3em">
37</wbr><wbr style="LINE-HEIGHT: 1.3em">
38</wbr><wbr style="LINE-HEIGHT: 1.3em">
39</wbr><wbr style="LINE-HEIGHT: 1.3em">
40</wbr><wbr style="LINE-HEIGHT: 1.3em">
41</wbr><wbr style="LINE-HEIGHT: 1.3em">
42</wbr><wbr style="LINE-HEIGHT: 1.3em">
43</wbr><wbr style="LINE-HEIGHT: 1.3em">
44</wbr><wbr style="LINE-HEIGHT: 1.3em">
45</wbr><wbr style="LINE-HEIGHT: 1.3em">
46</wbr><wbr style="LINE-HEIGHT: 1.3em">
47</wbr><wbr style="LINE-HEIGHT: 1.3em">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<html>
<head>
<meta http-equiv="Content-Type"</wbr><wbr style="LINE-HEIGHT: 1.3em"> content="text/html; charset=BIG5"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<title>Insert title here</title>

<script src="dwr/interface/Chat.js"</wbr><wbr style="LINE-HEIGHT: 1.3em"> type="text/javascript"</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script src="dwr/engine.js"</wbr><wbr style="LINE-HEIGHT: 1.3em"> type="text/javascript"</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script src="dwr/util.js"</wbr><wbr style="LINE-HEIGHT: 1.3em"> type="text/javascript"</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>

<script type="text/javascript"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
function sendMessage() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    var text = DWRUtil.getValue("text"</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    DWRUtil.setValue("text"</wbr><wbr style="LINE-HEIGHT: 1.3em">, ""</wbr><wbr style="LINE-HEIGHT: 1.3em">);
    Chat.addMessage(text, gotMessages);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function gotMessages(messages) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
    var chatlog = ""</wbr><wbr style="LINE-HEIGHT: 1.3em">;
    <wbr>for</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> (var data in messages) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
        chatlog = "<div>"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + messages[data].text +
            "</div>"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + chatlog;
    }</wbr><wbr style="LINE-HEIGHT: 1.3em">
    DWRUtil.setValue("chatlog"</wbr><wbr style="LINE-HEIGHT: 1.3em">, chatlog);
  setTimeout("queryMessage()"</wbr><wbr style="LINE-HEIGHT: 1.3em">, 2000);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">

function queryMessage() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
  Chat.getMessages(gotMessages);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
</script>

</head>
<body>

<p>
  Your Message:
  <input id="text"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
  <input type="button"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="Send"</wbr><wbr style="LINE-HEIGHT: 1.3em">
      onclick="sendMessage()"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
</p>

<p>Messages:</p>
<div id="chatlog"</wbr><wbr style="LINE-HEIGHT: 1.3em">></div>

</body>
</html>



當List物件傳回時,它成為gotMessages(messages)中的messages物件,而messages物件中包括 Message物件轉換後對應的JavaScript物件,由於我們已經設定了Converter,所以可以用messages[data].text來 取得傳回的訊息…

簡單抓個畫面…
</wbr><wbr></wbr><wbr>
分享到:
评论

相关推荐

    DWR3参考资料

    DWR3是DWR的第三个主要版本,它提供了改进的功能和性能,尤其在实时数据推送方面。在DWR3中,可以实现后台向Web浏览器实时推送消息,这对于创建交互性强、实时更新的应用程序非常有用,比如在线聊天室或股票交易应用...

    Dwr3+Spring3 全注解 annotation 方式

    本篇文章将详细介绍如何结合Dwr3和Spring3,利用全注解的方式进行集成与配置。 首先,我们需要理解Dwr3的基本概念。DWR3是DWR的第三个主要版本,它提供了一种简单的方法来实现在Web应用程序中调用服务器端的Java...

    DWR3.rar

    压缩包内的"DWR中文文档2.pdf"很可能是DWR3的中文用户指南或开发者手册,对于学习和使用DWR3框架具有很高的参考价值,详细介绍了如何配置、使用DWR以及解决常见问题。"dwr.rar"可能包含了DWR的源码或者库文件,便于...

    dwr3api+DWR文档.pdf

    《dwr3api+DWR文档.pdf》提供了关于DWR 3.x版本的详细信息,包括API参考和初级入门指南。这份文档可能涵盖了以下关键知识点: 1. **安装与配置**:如何在你的Java应用服务器上集成DWR,配置DWR的XML配置文件(dwr....

    DWR3消息推送(聊天Demo)

    在这个"DWR3消息推送(聊天Demo)"项目中,开发者提供了一个使用DWR3实现的简单聊天应用,让我们来详细了解一下这个示例中的关键知识点。 首先,我们要理解DWR3的核心特性。DWR3是DWR(Direct Web Remoting)的第三个...

    dwr3.x demo 实例 例子

    DWR3.x是DWR的一个版本,提供了许多增强的功能和改进,使得开发人员能够更方便地构建动态、交互式的Web应用。 在这个"Dwr3.x demo 实例 例子"中,我们可以学习到以下几个关键知识点: 1. **反转Ajax**:DWR的核心...

    dwr3推送消息

    在DWR3中,"推送消息"功能是其特性之一,它使得服务器能够主动向客户端推送数据,而不仅仅是响应客户端的请求。这种技术通常被称为Comet或长轮询,可以用于实现实时通信,如聊天应用、股票报价、在线游戏等场景。 ...

    dwr3所需jar包

    在这个“dwr3所需jar包”中,我们主要关注的是DWR 3.0版本的相关库文件。 在JavaWeb开发中,DWR作为一个强大的工具,使得前端和后端能够更有效地交互。它提供了以下核心特性: 1. **远程方法调用(Remote Method ...

    dwr3消息推送

    DWR3是DWR的一个版本,提供了更加强大和灵活的特性,包括异步通信、AJAX支持以及实时消息推送等。 在"消息推送"这一场景下,DWR3扮演了关键角色。它能够实现在一个页面上发送的消息,被其他页面实时接收和显示。...

    spring3mvc+hibernate4+spring-security3+dwr3整合架包

    本篇文章将深入探讨“spring3mvc+hibernate4+spring-security3+dwr3整合架包”中的核心技术和概念,帮助开发者理解如何利用这些组件来创建强大的Java Web应用。 首先,Spring MVC(Model-View-Controller)是Spring...

    dwr3_helloword入门

    3. 配置dwr.xml,指定暴露给JavaScript的Java类和方法。 4. 在web.xml中配置DWRControlServlet。 5. 引入必要的JavaScript文件到HTML页面。 6. 使用JavaScript调用Java方法,并定义回调函数处理返回数据。 通过这个...

    Struts2,Hibernate5,Dwr3

    Struts2、Hibernate5和DWR3是三个在Java Web开发中广泛应用的开源框架,它们分别专注于MVC(模型-视图-控制器)架构、对象关系映射(ORM)以及远程脚本(Remote Scripting)。这三者的整合为开发者提供了强大的工具...

    dwr3实现推送功能

    在DWR 3版本中,它提供了丰富的API和工具,使得开发者能够更加方便地构建富客户端Web应用。本篇文章将详细讲解如何利用DWR 3实现推送功能。 1. **DWR 3 的基本概念** DWR 3 提供了一种安全、高效的机制,使得...

    DWR3实现服务器端向客户端精确推送消息

    在“DWR3实现服务器端向客户端精确推送消息”这一主题中,我们将深入探讨如何利用DWR3进行服务器到客户端的消息推送,以及这种技术的优势和应用。 首先,理解DWR3的工作原理是至关重要的。DWR3通过建立一个安全的...

    dwr3ReverseAjax示例

    在这个“dwr3ReverseAjax示例”中,我们将深入探讨如何利用DWR 3.x版本来构建一个基于Ajax的简单Web聊天应用。 首先,DWR的核心功能是通过HTTP协议实现在客户端JavaScript和服务器端Java之间的远程方法调用(Remote...

    dwr3与ssh 开发的webim

    【标题】"dwr3与ssh 开发的webim"涉及的主要知识点是使用Direct Web Remoting (DWR) 框架与Struts2(S)和Hibernate(H)集成来构建一个实时的Web聊天应用。DWR允许JavaScript在客户端与Java在服务器端之间进行直接...

    dwr2.0.5.jar&dwr2.0.6.jar&dwr3.rc1.jar

    在这个场景中,我们关注的是DWR的三个不同版本的JAR文件:dwr2.0.5.jar、dwr2.0.6.jar以及dwr3.rc1.jar。 1. **DWR 2.0.x 版本**: DWR 2.0.x 是DWR的一个较早版本系列,其中2.0.5和2.0.6是两个连续的小版本更新。...

    struts2.1 spring2.5 ibatis2.3 dwr3 annotation配置 集成

    struts2.1 spring2.5 ibatis2.3 dwr3 annotation配置 集成 此中例子不完整. 如要下载:http://download.csdn.net/source/2138885

    spring3+dwr3实现聊天功能

    本篇将详细介绍如何利用Spring3和DWR3创建聊天功能,以及DWR的Server Push技术在其中的作用。 首先,Spring3是一个全面的Java企业级应用开发框架,提供了依赖注入、AOP(面向切面编程)、MVC(模型-视图-控制器)等...

    dwr3 中文示例

    DWR3是其第三个主要版本,提供了许多增强的功能和改进,旨在简化AJAX开发,提高用户体验。 DWR3中文示例是一个翻译自官方WAR包的资源,旨在帮助中国开发者更好地理解和使用DWR框架。这个示例集包含了详细的中文文档...

Global site tag (gtag.js) - Google Analytics