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/ 查看几个
示例。
下载它的源代码 也是一个很不错的学习的示例