function bankmsg(){
var bank = document.getElementById("bank_msg").value;
$.ajax({
'url':'getbanklist.ajax?timeStamp=' + new Date().getTime(),
'type':'post',
'data':'bank_name='+bank,
'contentType': 'application/x-www-form-urlencoded; charset=utf-8',
'dataType':'json',
'success':function(data){
$('#bank_lhh').empty();
for(i = 0;i < data.length;i ++){
var s = data[i];
$('#bank_lhh')
.append('' );
}
},
'error':function(){
//服务器处理出错,会执行该函数。
}
});
return true;
}
servlet部分:
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
String uri = request.getRequestURI();
String action = uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
if(action.equals("/getbanklist")){
String bank_name = request.getParameter("bank_name");
HLog.m_messagelog.debug("bank_name:" + bank_name);
List
List
if(list!=null){
for(int i = 0 ;i < list.size(); i ++){
BankListTable s = new BankListTable();
s.setBank_lhh(list.get(i).get(0));
s.setBank_name(list.get(i).get(1));
s.setBank_top(list.get(i).get(2));
banklist.add(s);
}
JSONArray arry = JSONArray.fromObject(banklist);
String jsonStr = arry.toString();
//System.out.println(jsonStr);
out.println(jsonStr);
}
}
}
WEB—INF下的web.xml配置部分:
jsp部分: