package dataserver;
import org.xml.sax.helpers.*;
import org.xml.sax.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/** *//**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) yaoqi 2006</p>
*
* <p>Company: scut_eb</p>
*
* @author not attributable
* @version 1.0
*/
public class weatherBean extends DefaultHandler {int i=1;String weather[]={"",""};
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
String when="";
if("yweather:forecast".equals(qName)) {if(i==1){when="今日";}else{when="明日";}
String s_date = attributes.getValue(1);
Date date = null;
try {
date = new SimpleDateFormat("dd MMM yyyy", Locale.US).parse(s_date);
}
catch (Exception e) {
e.printStackTrace();
throw new SAXException("Cannot parse date: " + s_date);
}
int low = Integer.parseInt(attributes.getValue(2));
int high = Integer.parseInt(attributes.getValue(3));
String text = attributes.getValue(4);
int code = Integer.parseInt(attributes.getValue(5));
weather[i-1]=when+weather(text) + ","+wherewind(code)+low + "-" + high+"℃";
i++;
}
super.startElement(uri, localName, qName, attributes);
}
public String weather(String eng){
String chs="";
if(eng.equals("Clear")){chs="清爽无云";}
else if(eng.equals("Sunny")){chs="阳光照耀";}
else if(eng.equals("Partly Cloudy")){chs="局部有云";}
else if(eng.equals("Mostly Clear")){chs="貌似无云";}
else if(eng.equals("Mostly Sunny")){chs="点点云朵";}
else if(eng.equals("Mostly Cloudy")){chs="云彩多多";}
else if(eng.equals("Cloudy")){chs="阴云密布";}
else if(eng.equals("Sunny/Wind")){chs="晴转多云";}
else if(eng.equals("AM Clouds/PM Sun/Wind")){chs="多云转晴";}
else if(eng.equals("AM Showers")){chs="清晨小雨";}
else{chs=eng;}
return chs;}
public String wherewind(int a)
{
String wind="error";
if(a>337 && a<=360){return "北风";}
else if(a>=0 && a<=22){return "北风";}
else if(a>22 && a<=67){return "东北风";}
else if(a>67 && a<=112){return "东风";}
else if(a>112 && a<=157){return "东南风";}
else if(a>157 && a<=202){return "南风";}
else if(a>202 && a<=247){return "西南风";}
else if(a>247 && a<=292){return "西风";}
else if(a>292 && a<=337){return "西北风";}
return wind;
}
public String getWeather(int i){
return weather[i];}
}
jsp网页抓取天气预报源代码
5星 · 超过95%的资源 需积分: 13 170 浏览量
2009-06-02
17:31:40
上传
评论 1
收藏 5KB RAR 举报
「已注销」
- 粉丝: 21
- 资源: 324
最新资源
- NetOps-py通过sftp替换网络设备启动文件
- STM32单片机FPGA毕设电路原理论文报告任务驱动教学法在单片机课程教学中的应用
- STM32单片机FPGA毕设电路原理论文报告任务驱动法在单片机教学中的应用
- STM32单片机FPGA毕设电路原理论文报告人造金刚石压机智能化压力测控系统设计
- 以某列为依据匹配多项(Excel版)
- STM32单片机FPGA毕设电路原理论文报告人体短臂离心机实验台的显示控制系统
- STM32单片机FPGA毕设电路原理论文报告人工气候室监控系统的环境控制器研究
- STM32单片机FPGA毕设电路原理论文报告染整自动线张力控制系统的设计
- 数据挖掘与机器学习-实验
- 基于Linux系统Nginx的动态网站的LNMP环境源码包
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页