1.加入struts的标准jar包

2.加入struts与json的jar包

3.配置web.xml文件

4.action类中代码
public class AjaxAction2 extends ActionSupport {
private Map<String,Object> map;
public Map<String, Object> getMap() {
return map;
}
@Override
public String execute() throws Exception {
map=new HashMap<>();
map.put("name", "张三");
map.put("age", 15);
map.put("address", "杭州");
return super.execute();
}
}
5.struts.xml文件的代码

6.网页代码
<html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="jquery/jquery-3.2.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#dj").click(function(){ $.post("ajaxAction2","name=zs",function(msg){ alert(msg.name); },"json"); }); }); </script> </head> <body> <button id="dj">点击</button> </body> </html>
由于我注册帅哥发现被人已经注册过,所以就注册个帅哥的爸爸也不错.帅哥毕竟是我生的.哈哈哈
浙公网安备 33010602011771号