【關(guān)注】ajaxnet4j
作者blog:? http://blog.joycode.com/percyboy
SourceForge 站點(diǎn):http://ajaxnet4j.sourceforge.net
看1 個(gè)官方示例:
它是怎么用javascript 調(diào)后臺(tái) java方法的.
1.hello word
- Import the "ajaxnet4j" taglib;
- Register the "ajaxnet4j.demo.BasicDemo" class;
- In the JavaScript function "test1", call the HelloWorld method *directly*;
- Receiving value from ".value" and alert it.
Server-side Java codes:
package?ajaxnet4j.demo;
public?class?BasicDemo?{
????@ajaxnet4j.AjaxMethod
????public?String?HelloWorld(String?name)?{
????????return?"Hello,?"?+?name?+?"!";
????}
}
Note the annotation "ajaxnet4j.AjaxMethod", it marks the method "HelloWorld" as an ajax method, which is ready to be accessed in browser-side JavaScript.
JSP HTML and JavaScripts:
<%@?taglib?uri="http://ajaxnet4j.sourceforge.net"?prefix="ajaxnet4j"?%>
<html>
<head>
???????<ajaxnet4j:register?className="ajaxnet4j.demo.BasicDemo"></ajaxnet4j:register>
</head>
<body><form>
????<script?type="text/javascript">
????????function?test1()?{
????????????var?txt?=?document.getElementById("txtName");
????????????alert(ajaxnet4j.demo.BasicDemo.HelloWorld(txt.value).value);
????????}
????</script>
????<p>Fill?a?name?in?the?textbox?below?and?click?the?button?on?the?right:</p>
????<input?type="text"?id="txtName"?/>
????<input?type="button"?value="Test"?onclick="javascript:test1()"?/>
</form></body>
</html>
查看幾個(gè)示例。
下載它的源代碼 也是一個(gè)很不錯(cuò)的學(xué)習(xí)的示例
posted on 2006-09-22 09:13 record java and net 閱讀(2068) 評(píng)論(13) 編輯 收藏 所屬分類(lèi): AJAX