- 浏览: 86458 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
chencang:
太感谢您了!!!!
Loadrunner录制脚本无法打开IE的问题解决方法 -
cyf-123456:
有点乱
Hibernate Gossip: 建立SQL查詢 -
清风朗月:
能不能修改好了?
Jmock2.0 -
清风朗月:
写的嘛玩意呀?
Jmock2.0 -
jhui:
@before 没有执行
是为什么呢?》
我用的是juni ...
JUnit 4 使用 Java 5 中的注解(annotation)
Java 開發人員與網頁設計人員的橋樑 DWR…呃!我懶得寫簡介了…直接來看看可以做什麼吧!…
請先到 http://getahead.ltd.uk/dwr/<wbr> 下載 dwr.jar,放到WEB-INF/lib下…
負責處理客戶端請求,並呼叫Java物件的是DWRServlet,DWR其實也有些Model 2的味道,只是View的這一層比較弱,因為放到客戶端的JavaScript應用程式中…
在web.xml中加入DWRServlet…
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">
<?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">>
<display-name>
ajaxDWR</display-name>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern></wbr><wbr style="LINE-HEIGHT: 1.3em">
</servlet-mapping></wbr><wbr style="LINE-HEIGHT: 1.3em">
</web-app></wbr><wbr style="LINE-HEIGHT: 1.3em">
接下來寫個簡單的Hello吧!
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">
<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"> Hello {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> String hello(String name) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> "哈囉!"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + name + "!您的第一個DWR!"</wbr><wbr style="LINE-HEIGHT: 1.3em">;
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
客戶端要呼叫這個Java物件,傳給它參數,而後傳回一個字串,客戶端再顯示這個字串,神奇?其實是要告訴DWRServlet這件事,這需要一個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">
<?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="Hello"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<param name="class"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="onlyfun.caterpillar.Hello"</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
</create>
</allow>
</dwr>
creator設定為new,表示使用Hello的無參數建構子來生成物件,javascript設定為Hello,表示客戶端JavaScript程式可以使用Hello來呼叫對應的onlyfun.caterpillar.Hello物件。
來寫個客戶端的網頁,當中有一個輸入欄位…
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">
<!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>第一個DWR程式</title>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/interface/Hello.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/engine.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/util.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='hello.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
</head>
<body>
<input id="user"</wbr><wbr style="LINE-HEIGHT: 1.3em"> type="text"</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
<input type='button'</wbr><wbr style="LINE-HEIGHT: 1.3em"> value='哈囉'</wbr><wbr style="LINE-HEIGHT: 1.3em"> onclick='hello();'</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
<div id="result"</wbr><wbr style="LINE-HEIGHT: 1.3em">></div>
</body>
</html>
dwr/interface/Hello.js是由DWRServlet根據dwr.xml中的設定生成的,engine.js負責客戶端伺服端溝通,util.js是一些好用的JavaScript程式,可以讓您少寫很多JavaScript。
hello.js是我們自訂的函式,按下按鈕後,會呼叫當中的hello()函式:
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">
function hello() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
var user = $('user'</wbr><wbr style="LINE-HEIGHT: 1.3em">).value;
Hello.hello(user, callback);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function callback(msg) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('result'</wbr><wbr style="LINE-HEIGHT: 1.3em">, msg);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
${'user'}取得輸入欄位的DOM物件,value取得當中的欄位值,而後呼叫Hello.hello(),並將value當作參數傳送… 結果是呼叫Server端的Hello Java物件,當結果傳回後,會呼叫JavaScript的callback函式,DWRUtil的setValue()方法會將傳回的msg設定給指定 id的DOM,結果就是…啥!AJAX的功能在哪…就這個而言就是發出非同步請求,而回應不用Refresh頁面啦!
</wbr><wbr></wbr><wbr>
好啦!這個無聊的Hello DWR可以做啥!…XD
已經可以讓您做個簡單的文字提示功能了…像這個…
http://caterpillar.onlyfun.net/Gossip/index.html</wbr><wbr>
把滑鼠指到書的照片上,會顯示提示文字,這些提示文字本身不是存在網頁上的,而是在Server端,當滑鼠指到書上時,會用Request object去抓,然後顯示在框框中…
當然!我的網站只支援PHP,所以那不是DWR完成的功能,而且我是直接用Request object跟DOM去慢慢刻的…對初學者來說已經有些麻煩了…XD
不過!用DWR就可以很簡單完成這個功能…
先寫個Java類別吧!會抓properties檔案中的文字訊息,例如…
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">
<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.ResourceBundle;
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>class</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Book {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ResourceBundle resource;
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Book() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
resource = ResourceBundle.getBundle("book"</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"> String getDescription(String key) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> resource.getString(key);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
從程式中就知道,它會去抓book_zh_TW.properties的資料,這不是重點啦!只是Java的一個功能,我們要看的是DWR,不過先把book_zh_TW.properties準備好…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
java=Java 學習筆記的介紹 … BlaBla...
spring=Spring 技術手冊的介紹…BlaBla...
ajax=Ajax in action 中文版的介紹…
唔!裏頭是中文字,自己用native2ascii轉換吧…這也不是重點…我們是要看DWR怎麼做到文字提示功能…
一樣的…要開放這個Book物件,在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">
<?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="Book"</wbr><wbr style="LINE-HEIGHT: 1.3em"> scope="application"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<param name="class"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="onlyfun.caterpillar.Book"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
</create>
</allow>
</dwr>
scope設定為application,表示這個Book物件在整個應用程式階段都活著。
然後,客戶端寫個網頁…
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">
<!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">>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/interface/Book.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/engine.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/util.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='book.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<title>個人著/譯作</title>
</head>
<body>
<div id="ajax"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=AXP011800"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Ajax in action 中文版"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Ajax in action 中文版"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/ajax_in_action_c.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em"> vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<div id="spring"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=ACL021000"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Spring 技術手冊"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Spring 技術手冊"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/SpringTech_S.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em"> vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<div id="java"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=ACL020931"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Java 學習筆記"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Java 學習筆記"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/JavaGossip_Cover_Small.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em">
vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<br/><br/><br/><br/><br/><br/>
<div id="info"</wbr><wbr style="LINE-HEIGHT: 1.3em">></div>
</body>
</html>
重點在於onmouseover跟onmouseout,滑鼠移入與移出時會呼叫的函式,還有最下面的info,抓回來的書籍介紹會放到當中…
book.js如下,簡單的很…
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">
function getBookData(ele) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
Book.getDescription(ele.id, setBookData);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function setBookData(description) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('info'</wbr><wbr style="LINE-HEIGHT: 1.3em">, description);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function clearData() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('info'</wbr><wbr style="LINE-HEIGHT: 1.3em">, ''</wbr><wbr style="LINE-HEIGHT: 1.3em">);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
程式很簡單,我懶得解釋了…XD
看一下畫面好了…這是滑鼠移到 Ajax in action中文版<wbr style="LINE-HEIGHT: 1.3em"></wbr></wbr><wbr> 上的介紹畫面…
</wbr><wbr></wbr><wbr>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1186566
請先到 http://getahead.ltd.uk/dwr/<wbr> 下載 dwr.jar,放到WEB-INF/lib下…
負責處理客戶端請求,並呼叫Java物件的是DWRServlet,DWR其實也有些Model 2的味道,只是View的這一層比較弱,因為放到客戶端的JavaScript應用程式中…
在web.xml中加入DWRServlet…
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">
<?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">>
<display-name>
ajaxDWR</display-name>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<description>
</description>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern></wbr><wbr style="LINE-HEIGHT: 1.3em">
</servlet-mapping></wbr><wbr style="LINE-HEIGHT: 1.3em">
</web-app></wbr><wbr style="LINE-HEIGHT: 1.3em">
接下來寫個簡單的Hello吧!
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">
<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"> Hello {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> String hello(String name) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> "哈囉!"</wbr><wbr style="LINE-HEIGHT: 1.3em"> + name + "!您的第一個DWR!"</wbr><wbr style="LINE-HEIGHT: 1.3em">;
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
客戶端要呼叫這個Java物件,傳給它參數,而後傳回一個字串,客戶端再顯示這個字串,神奇?其實是要告訴DWRServlet這件事,這需要一個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">
<?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="Hello"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<param name="class"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="onlyfun.caterpillar.Hello"</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
</create>
</allow>
</dwr>
creator設定為new,表示使用Hello的無參數建構子來生成物件,javascript設定為Hello,表示客戶端JavaScript程式可以使用Hello來呼叫對應的onlyfun.caterpillar.Hello物件。
來寫個客戶端的網頁,當中有一個輸入欄位…
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">
<!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>第一個DWR程式</title>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/interface/Hello.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/engine.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/util.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='hello.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
</head>
<body>
<input id="user"</wbr><wbr style="LINE-HEIGHT: 1.3em"> type="text"</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
<input type='button'</wbr><wbr style="LINE-HEIGHT: 1.3em"> value='哈囉'</wbr><wbr style="LINE-HEIGHT: 1.3em"> onclick='hello();'</wbr><wbr style="LINE-HEIGHT: 1.3em"> />
<div id="result"</wbr><wbr style="LINE-HEIGHT: 1.3em">></div>
</body>
</html>
dwr/interface/Hello.js是由DWRServlet根據dwr.xml中的設定生成的,engine.js負責客戶端伺服端溝通,util.js是一些好用的JavaScript程式,可以讓您少寫很多JavaScript。
hello.js是我們自訂的函式,按下按鈕後,會呼叫當中的hello()函式:
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">
function hello() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
var user = $('user'</wbr><wbr style="LINE-HEIGHT: 1.3em">).value;
Hello.hello(user, callback);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function callback(msg) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('result'</wbr><wbr style="LINE-HEIGHT: 1.3em">, msg);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
${'user'}取得輸入欄位的DOM物件,value取得當中的欄位值,而後呼叫Hello.hello(),並將value當作參數傳送… 結果是呼叫Server端的Hello Java物件,當結果傳回後,會呼叫JavaScript的callback函式,DWRUtil的setValue()方法會將傳回的msg設定給指定 id的DOM,結果就是…啥!AJAX的功能在哪…就這個而言就是發出非同步請求,而回應不用Refresh頁面啦!
</wbr><wbr></wbr><wbr>
好啦!這個無聊的Hello DWR可以做啥!…XD
已經可以讓您做個簡單的文字提示功能了…像這個…
http://caterpillar.onlyfun.net/Gossip/index.html</wbr><wbr>
把滑鼠指到書的照片上,會顯示提示文字,這些提示文字本身不是存在網頁上的,而是在Server端,當滑鼠指到書上時,會用Request object去抓,然後顯示在框框中…
當然!我的網站只支援PHP,所以那不是DWR完成的功能,而且我是直接用Request object跟DOM去慢慢刻的…對初學者來說已經有些麻煩了…XD
不過!用DWR就可以很簡單完成這個功能…
先寫個Java類別吧!會抓properties檔案中的文字訊息,例如…
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">
<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.ResourceBundle;
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> <wbr>class</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Book {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>private</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> ResourceBundle resource;
<wbr>public</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> Book() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
resource = ResourceBundle.getBundle("book"</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"> String getDescription(String key) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
<wbr>return</wbr><wbr></wbr></wbr><wbr style="LINE-HEIGHT: 1.3em"> resource.getString(key);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
從程式中就知道,它會去抓book_zh_TW.properties的資料,這不是重點啦!只是Java的一個功能,我們要看的是DWR,不過先把book_zh_TW.properties準備好…
1</wbr><wbr style="LINE-HEIGHT: 1.3em">
2</wbr><wbr style="LINE-HEIGHT: 1.3em">
3</wbr><wbr style="LINE-HEIGHT: 1.3em">
java=Java 學習筆記的介紹 … BlaBla...
spring=Spring 技術手冊的介紹…BlaBla...
ajax=Ajax in action 中文版的介紹…
唔!裏頭是中文字,自己用native2ascii轉換吧…這也不是重點…我們是要看DWR怎麼做到文字提示功能…
一樣的…要開放這個Book物件,在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">
<?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="Book"</wbr><wbr style="LINE-HEIGHT: 1.3em"> scope="application"</wbr><wbr style="LINE-HEIGHT: 1.3em">>
<param name="class"</wbr><wbr style="LINE-HEIGHT: 1.3em"> value="onlyfun.caterpillar.Book"</wbr><wbr style="LINE-HEIGHT: 1.3em">/>
</create>
</allow>
</dwr>
scope設定為application,表示這個Book物件在整個應用程式階段都活著。
然後,客戶端寫個網頁…
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">
<!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">>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/interface/Book.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/engine.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='dwr/util.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<script type='text/javascript'</wbr><wbr style="LINE-HEIGHT: 1.3em"> src='book.js'</wbr><wbr style="LINE-HEIGHT: 1.3em">></script>
<title>個人著/譯作</title>
</head>
<body>
<div id="ajax"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=AXP011800"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Ajax in action 中文版"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Ajax in action 中文版"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/ajax_in_action_c.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em"> vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<div id="spring"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=ACL021000"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Spring 技術手冊"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Spring 技術手冊"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/SpringTech_S.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em"> vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<div id="java"</wbr><wbr style="LINE-HEIGHT: 1.3em"> onmouseover="getBookData(this);"</wbr><wbr style="LINE-HEIGHT: 1.3em">
onmouseout="clearData();"</wbr><wbr style="LINE-HEIGHT: 1.3em">><a
href="http://www.gotop.com.tw/waweb2004/home/home.aspx?pg=HM010X&bn=ACL020931"</wbr><wbr style="LINE-HEIGHT: 1.3em">><small><img
style="border: 0px solid ; width: 80px; height: 110px; float: left;"</wbr><wbr style="LINE-HEIGHT: 1.3em">
alt="Java 學習筆記"</wbr><wbr style="LINE-HEIGHT: 1.3em"> title="Java 學習筆記"</wbr><wbr style="LINE-HEIGHT: 1.3em">
src="images/JavaGossip_Cover_Small.jpg"</wbr><wbr style="LINE-HEIGHT: 1.3em"> hspace="10"</wbr><wbr style="LINE-HEIGHT: 1.3em">
vspace="2"</wbr><wbr style="LINE-HEIGHT: 1.3em">></small></a></div>
<br/><br/><br/><br/><br/><br/>
<div id="info"</wbr><wbr style="LINE-HEIGHT: 1.3em">></div>
</body>
</html>
重點在於onmouseover跟onmouseout,滑鼠移入與移出時會呼叫的函式,還有最下面的info,抓回來的書籍介紹會放到當中…
book.js如下,簡單的很…
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">
function getBookData(ele) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
Book.getDescription(ele.id, setBookData);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function setBookData(description) {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('info'</wbr><wbr style="LINE-HEIGHT: 1.3em">, description);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
function clearData() {</wbr><wbr style="LINE-HEIGHT: 1.3em">
DWRUtil.setValue('info'</wbr><wbr style="LINE-HEIGHT: 1.3em">, ''</wbr><wbr style="LINE-HEIGHT: 1.3em">);
}</wbr><wbr style="LINE-HEIGHT: 1.3em">
程式很簡單,我懶得解釋了…XD
看一下畫面好了…這是滑鼠移到 Ajax in action中文版<wbr style="LINE-HEIGHT: 1.3em"></wbr></wbr><wbr> 上的介紹畫面…
</wbr><wbr></wbr><wbr>
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1186566
相关推荐
dwr 1 jar dwr 1 jar
- DWR 1.x是其早期版本,引入了基本的远程方法调用(RMI)概念到Web应用,使开发者能够轻松地创建动态交互的页面。 - 此版本可能包含了基本的AJAX支持,允许异步更新部分网页而无需整个页面刷新。 - 它可能提供了...
这个压缩包包含了DWR的三个主要版本:DWR1.0、DWR2.0和DWR3.0的jar包,这些jar包是运行DWR应用的核心组件。 DWR1.0: DWR1.0是DWR项目的早期版本,主要目标是简化Web应用中的异步通信。在这个版本中,DWR提供了一个...
Ext 2.0.1 和 DWR 1是两个在Web开发中常用的技术框架,用于构建富客户端应用程序。本实例主要是介绍如何结合这两者来创建一个实时编辑的表格,而无需借助数据库,非常适合初学者入门。 Ext是一个JavaScript库,专为...
【Ext 2.0.1】与【DWR 1】是本文介绍的重点技术,它们在AJAX应用中被用于创建一个实时编辑的表格。AJAX(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。在本...
在这种情况下,`dwr-invoker1`Servlet会处理`/dwr1/*`的请求,并使用`dwr1.xml`作为配置文件。 在DWR中,Java方法的调用非常直观。例如,假设有一个名为`UserService`的Java类,其中有一个`getUserInfo`方法,可以...
DWR 2.0版本是在DWR 1.x基础上的升级,改进了性能和易用性,同时也增加了更多的特性。 DWR的核心功能是将Java对象暴露给JavaScript,使得在不刷新页面的情况下,前端可以调用后端的方法,更新页面数据。这种通信...
<param-value>WEB-INF/dwr1.xml <param-name>config-2 <param-value>WEB-INF/dwr2.xml ``` - 如果有多个Servlet,每个Servlet可以有自己的`dwr.xml`配置,如: ```xml <servlet-name>dwr-invoker1 ...
如果使用的是DWR 1.x版本,则`servlet-class`应为`uk.ltd.getahead.dwr.DWRServlet`。虽然1.x版本与2.x版本兼容,但推荐使用较新版本。 ##### 创建`dwr.xml` `dwr.xml`文件定义了DWR可以创建和远程调用的类,以及...
这里,`config-1`和`config-2`是参数名,它们的值分别指向`dwr1.xml`和`dwr2.xml`。没有指定的`config-`参数默认会读取`WEB-INF/dwr.xml`。 - **多个Servlet,每个Servlet对应一个或多个`dwr.xml`**:如果你有多...
DWR2.0是DWR的一个版本,它在DWR1.x的基础上做了很多改进,增强了性能和易用性。而Spring框架则是一个广泛使用的轻量级Java企业级应用开发框架,它提供了一种模块化和灵活的方式来构建和管理应用程序。 在DWR2.0中...
<param-value>WEB-INF/dwr1.xml <param-name>config-2 <param-value>WEB-INF/dwr2.xml ``` - **多个Servlet,每个Servlet对应一个或多个`dwr.xml`**:你可以为每个Servlet配置不同的`dwr.xml`文件,如: ```...
<param-value>WEB-INF/dwr1.xml <param-name>config-2 <param-value>WEB-INF/dwr2.xml ``` ###### 3.2 多个servlet,各自对应一个或多个dwr.xml文件 当项目复杂度增加时,可能需要为不同的功能模块创建独立的...
1. **下载DWR库:** - 首先,访问官方网站 [http://getahead.ltd.uk/dwr/](http://getahead.ltd.uk/dwr/) 下载最新的`dwr.jar`文件。 - 将下载的`dwr.jar`放入项目的`WEB-INF/lib`目录下。 2. **配置Web.xml:** ...
1、 建立dwr.xml 配置文件 任何一个dwr.xml的文件都需要包含DWR DOCTYPE的声明行,格式如下: <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" ...
dwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwrdwr dwr
DWR2.0是DWR的一个重要版本,它在DWR1.x的基础上进行了许多改进和增强。 DWR的核心功能在于提供了一个安全、简单的API,使得JavaScript可以直接调用服务器端的Java方法,就像它们是本地函数一样。这种技术被称为...
1. **在`web.xml`中配置DWR** 在项目的`web.xml`文件中添加DWR的配置,这包括定义DWR Servlet以及其映射路径。具体配置如下: ```xml <servlet-name>dwr-invoker <servlet-class>uk.ltd.getahead.dwr....
在这个例子中,`dwr-invoker1`Servlet关联了`dwr1.xml`配置文件,并开启了调试模式。 在`dwr.xml`配置文件中,你可以定义哪些Java类和方法可以被客户端访问。例如: ```xml ``` 这将允许在JavaScript中...