package com.MarkNum; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; public class Hello { public String getMyName() { return "gengzg:"; } public String getMyNames(String str) { return "gengzg:" + str; } public JSONArray getMyNamess(String str, String str2) { JSONArray jsons = new JSONArray(); for (int i = 0; i < 10; i++) { JSONObject json = new JSONObject(); json.put("usrid", i); json.put("usrname", "耿宗国"+i); json.put("usrmobile", "13910536016"); jsons.add(json); } return jsons; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type='text/javascript' src='dwr/engine.js'></script> <script type='text/javascript' src='dwr/util.js'></script> <script type='text/javascript' src='dwr/interface/CASCO.js'></script> <script language="javascript"> function showMyNames() { CASCO.getMyNamess('aaaaaa', 'bbbbb', abc); } function abc(data) { window.alert(data[0].usrname); for (var i = 0; i < data.length; i++) { window.alert(data[i].usrname); } } function clearName() { demo1.value = ""; } </script> </head> <body> <input type="button" value="显示姓名" onclick="javascript:showMyNames()"> <input type="button" value="清空" onclick="javascript:clearName()"> <br> <input type="text" id="demo1"> <br> </body> </html>
<servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <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> </servlet-mapping>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd"> <dwr> <allow> <create creator="new" javascript="CASCO" scope="application"> <param name="class" value="com.MarkNum.Hello" /> </create> </allow> </dwr>