//获取气象局数据
@RequestMapping(value = "getAlert")
public void getdate(HttpServletResponse response) throws IOException{
String url = "http://www.szmb.gov.cn/data_cache/szWeather/alarm/szAlarm.js?"+Math.random();
// 地址对象
URL webUrl = null;
try {
webUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// 建立远程连接
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) webUrl.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
// 得到输入流
InputStream ins = conn.getInputStream();
// 字符读取流
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins,
"UTF-8"));
// 使用字符串构造器,将读取的每一行数据拼接起来
StringBuffer sb = new StringBuffer();
String content = null;
while ((content = bfr.readLine()) != null) {
sb.append(content);
}
// 关闭字符流
bfr.close();
@RequestMapping(value = "getAlert")
public void getdate(HttpServletResponse response) throws IOException{
String url = "http://www.szmb.gov.cn/data_cache/szWeather/alarm/szAlarm.js?"+Math.random();
// 地址对象
URL webUrl = null;
try {
webUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// 建立远程连接
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) webUrl.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
// 得到输入流
InputStream ins = conn.getInputStream();
// 字符读取流
BufferedReader bfr = new BufferedReader(new InputStreamReader(ins,
"UTF-8"));
// 使用字符串构造器,将读取的每一行数据拼接起来
StringBuffer sb = new StringBuffer();
String content = null;
while ((content = bfr.readLine()) != null) {
sb.append(content);
}
// 关闭字符流
bfr.close();