ajaxnet4j 是?
Ajax.NET Professional 的一個
Java 實現。
Ajax.NET
Professional 是 .NET 平臺下第一個、也是截至目前最流行的免費 Ajax 庫之一。
作者blog:?
http://blog.joycode.com/percyboySourceForge 站點:
http://ajaxnet4j.sourceforge.net看1 個官方示例:
它是怎么用javascript 調后臺 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>
詳細到
http://ajaxnet4j.sourceforge.net/ 查看幾個
示例。
下載它的源代碼 也是一個很不錯的學習的示例