赞
踩
html:
function getWeather(){
$.ajax({
type:”post”,//请求方式
url:”weather”,//发送请求地址
data:{//发送给数据库的数据
province:$(“#province”).val(),
site:$(“#site”).val()
},
dataType:”json”,
success:function(result){
console.log(result);
$(“#query”).html(result.value);
},
error : function(request, error) {
alert(“”Sorry, some unexpected errors happened. Please contact your system administrator””);
}
});
}
请选择地点:
辽宁
重庆
大连
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“gbk”);
String site=request.getParameter(“site”);
String province=request.getParameter(“province”);
WeatherUtil wu=new WeatherUtil();
int provinceCode = wu.getProvinceCode(province);
int cityCode = wu.getCityCode(provinceCode, site);
List weatherList = wu.getWeather(cityCode);
PrintWriter pw=response.getWriter();
ObjectMapper mapper = new ObjectMapper();
String result=mapper.writeValueAsString(weatherList);
pw.write(result);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。