struts json ajax整理

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>
原文地址:https://www.cnblogs.com/tony-hyn/p/7660008.html