Home  >  Article  >  Web Front-end  >  Use javascript to add weather display implementation ideas and codes to the page_javascript skills

Use javascript to add weather display implementation ideas and codes to the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:11:131329browse
复制代码 代码如下:

<%@ page language="java" pageEncoding="UTF-8"%>


<script> <br>function load(cid) <br>{ <br>var xmlhttp; <br>if (window.XMLHttpRequest) <br>{// code for IE7 , Firefox, Chrome, Opera, Safari <br>xmlhttp=new XMLHttpRequest(); <br>} <br>else <br>{// code for IE6, IE5 <br>xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); <br>} <br>xmlhttp.open("GET","date.jsp?cid=" cid,false); <br>xmlhttp.send(); <br>var obj = eval("(" xmlhttp.responseText ")"); <br>//var obj=JSON.parse(xmlhttp.responseText); //IE8以上 <br>document.getElementById("test").innerHTML=obj.weatherinfo.city ":" obj.weatherinfo.weather1 " " obj.weatherinfo.temp1; <br>} <br></script>


天气情况








date.jsp
复制代码 代码如下:

<%@ page language="java" import="java.net.*,java.io.*" pageEncoding="utf-8"%>
<%
String cid = request.getParameter("cid");
URL url = new URL("http://m.weather.com.cn/data/" cid ".html");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.connect();
InputStream cin = httpConn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(cin,"UTF-8"));
StringBuffer sb = new StringBuffer();
String rl = null;
while ((rl = reader.readLine()) != null)
sb.append(rl);
out.println(sb);
%>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn