点击按钮没有反应,没有进入$.post
//JsonAction.java public class JsonAction extends ActionSupport{ private static final long serialVersionUID = 1L; private JSONArray root; public String execute(){ List<User> list = new ArrayList<User>(); list.add(new User("zhangsan", 21)); list.add(new User("lisi", 22)); list.add(new User("wangwu", 23)); root = JSONArray.fromObject(list); System.out.println(root); return SUCCESS; } public JSONArray getRoot() { return root; } public void setRoot(JSONArray root) { this.root = root; } }
//User.java public class User { private String name; private int age; public User() { // TODO Auto-generated constructor stub } public User(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
//struts.xml <package name="default" namespace="/" extends="json-default"> <action name="ajax" class="my.action.AjaxAction" > </action> <action name="json" class="my.action.JsonAction"> <result type="json"> <param name="root">root</param> </result> </action> </package>
//Json.jsp <script type="text/javascript" src="js/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#btn1').click(function(){ $.post("json.action",function(data){ var infom = ""; for(var i;i<data.length;i++){ infom += "<tr><td>"+data[i].name+"</td><td>"+data[i].age+"</td></tr>"; } return $('#info').html(infom); }); }); }); </script> ... <body> <input type="button" id="btn1" value="Get the Json information"/><br> <table width="80%" align="center"> <thead> <tr> <td>姓名</td> <td>年龄</td> </tr> </thead> <tbody id="info"></tbody> </table> </body>
jar包
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
ezmorph-1.0.6.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
json-lib-2.3-jdk15.jar
log4j-1.2.17.jar
ognl-3.0.6.jar
struts2-core-2.3.15.1.jar
struts2-json-plugin-2.3.15.1.jar
xwork-core-2.3.15.1.jar
commons-beanutils-1.8.0.jar
commons-collections-3.1.jar
进入jsp点击按钮没有反应,原因在哪?