5

java前后台数据请求返回问题

图片说明![图片说明](https://img-ask.csdn.net/upload/201804/06/1522981219_852743.png)图片说明将后台list数据转化成jsonarray返回前台,前台访问list中元素的属性显示在下拉框中,执行只输出System.out.println("getDataset.java中2");哪里有问题?

后台.java代码
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String test_name = request.getParameter("testname");
System.out.println("test_name: "+test_name);
DBController con = new DBController(test_name);
//查找list
System.out.println("进入前");
List list = con.select(test_name);
System.out.println("getDataset.java中");
System.out.println("list:"+list.get(0).getDatasetPath());
System.out.println("getDataset.java中2");
JSONArray list1=JSONArray.fromObject(list);
System.out.println("getDataset.java中3");
response.setCharacterEncoding("UTF-8");//解决显示中文乱码问题
PrintWriter writer = response.getWriter();
writer.write(list1.toString());
writer.flush();
System.out.println("list:"+list.get(0).getId());
}
前台.jsp代码

 <div class="form-group" id="select_now">
        <label class="col-xs-3 control-label">选择已有数据集</label>
        <div class="col-xs-3">  
            <select class="form-control" name="select_dataset" id="select_dataset" onclick="getdatasets();">
            </select>
        </div>
      </div>

function getdatasets(){
$.ajax({
    type : "POST",
    url:"<%=contextPath%>/getDatasets",
    data : {
        type : "0",
        testname : "自动分类",
    },
    dataType : "text",
    async : false,
    context : null,
    success : function(list) {
        alert(typeof list);
         alert("成功1");
        //下拉菜单选项显示数据库名,值为数据库的真实地址
        $("#select_dataset").html('');
        //alert("成功2");
        for(var i = 0; i<list.length; i++){
            var inner = "";
            //alert("成功3");
            inner += "<option value='" + list.get(i).getDatasetPath() +"'>" + list.get(i).getDataset() + "</option>";
            $("#select_dataset").append(inner);
        }
        list=[];
        alert("成功5");
    }

})

}

查看全部
weixin_40729074
weixin_40729074
2018/04/06 01:41
  • java
  • select
  • json
  • list
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

7个回复