<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajax测试版</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('.button').click(function(){
        $.ajax({
            type:'POST',
            url:'SServlet?method=find1',
             data: {name:$("#name").val()},

            success:function(data){
                if(data.length>0){


                     $('.user').remove();
                     $('#id').append("<table class='user'></table>");
                      $('.user').append("<tr><th>平台编号</th></tr>");
                    $.each(data,function(index){

                        var tr;
                        tr='<td>'+data[index].name+'</td>';
                        $(".user").append('<tr>'+tr+'</tr>')
                    })


                    }

            },
            error:function(){
                $('#id').html("hehehe");
            }
        });
    });
});
</script>
</head>
<body>
<div>
<p class="p">点击按钮变换内容</p>
<button class="button">点击</button>
<input type="text" id="name">
<div id="id">
</div>
</div>
</body>
</html>
JSONArray array2 = new JSONArray();
for (int i = 0; i < list2.size(); i++) {
              JSONObject json2 = new JSONObject();
              json2.put("name", list2.get(i).getSTOCK_NAME());
              array2.add(json2);
          }

resp.setContentType("application/json");
          resp.setCharacterEncoding("utf-8");
          resp.getWriter().write(array2.toString());
12-17 00:17