提供盘扣式脚手架,盘扣式脚手架厂家,盘扣式脚手架价格,盘扣脚手架,轮扣式脚手架
  • 1
  • 2

脚手架租赁

"GBK"); String link="http://php.weather.sina.com.cn/xml.php

添加时间:2022-05-14

String getValue (String[] nodes) { if (inStream == null || root== null ) { return null ;}MapString, "status2" ,type: "post" 。

success: function (data) { document.getElementById( "weather" ).innerHTML=data;}});} 你能够在jsp页面中本身写个 而后直接访问页面 java 。

"temperature1" , temp);}}}}}}} return map;} /* public static void main(String[] args) throws UnsupportedEncodingException { System.out.println("请输入您须要查询的地点:"); Scanner input = new Scanner(System.in); String city = input.next(); String city_url = URLEncoder.encode(city。

null );} // 遍历第一节点 NodeList topNodes = root.getChildNodes(); if (topNodes != null ) { for ( int i = 0 ; i topNodes.getLength(); i++) {Node book = topNodes.item(i); if (book.getNodeType() == Node.ELEMENT_NODE) { for ( int j = 0 ; j nodes.length; j++) { for (Node node = book.getFirstChild(); node != null ; node = node.getNextSibling()) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals(nodes[j])) {String val = node.getTextContent();String temp = map.get(nodes[j]); if (temp != null !temp.equals( "" )) {temp = temp + ";" + val;} else {temp = val;}map.put(nodes[j], 工具类 javascript package com.ambow.invoic.utils; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.HashMap; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class WeatherUtil { InputStream inStream;Element root; public InputStream getInStream () { return inStream;} public void setInStream (InputStream inStream) { this .inStream = inStream;} public Element getRoot () { return root;} public void setRoot (Element root) { this .root = root;} public WeatherUtil () {} /** * 经过输入流来获取新浪接口信息 * @param inStream */ public WeatherUtil (InputStream inStream) { if (inStream != null ) { this .inStream = inStream;DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); try {DocumentBuilder domBuilder = domfac.newDocumentBuilder();Document doc = domBuilder.parse(inStream);root = doc.getDocumentElement();} catch (ParserConfigurationException e) {e.printStackTrace();} catch (SAXException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}} public WeatherUtil (String path) {InputStream inStream = null ; try {inStream = new FileInputStream(path);} catch (FileNotFoundException e1) {e1.printStackTrace();} if (inStream != null ) { this .inStream = inStream;DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); try {DocumentBuilder domBuilder = domfac.newDocumentBuilder();Document doc = domBuilder.parse(inStream);root = doc.getDocumentElement();} catch (ParserConfigurationException e) {e.printStackTrace();} catch (SAXException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}} public WeatherUtil (URL url) {InputStream inStream = null ; try {inStream = url.openStream();} catch (IOException e1) {e1.printStackTrace();} if (inStream != null ) { this .inStream = inStream;DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance(); try {DocumentBuilder domBuilder = domfac.newDocumentBuilder();Document doc = domBuilder.parse(inStream);root = doc.getDocumentElement();} catch (ParserConfigurationException e) {e.printStackTrace();} catch (SAXException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}} /** * * @param nodes * @return 单个节点多个值以分号分隔 */ public MapString, "GBK"); String link="http://php.weather.sina.com.cn/xml.php?city="+city_url+"password=DJOYnieT8234jlsKday=0"; URL url; try { url = new URL(link); WeatherUtil parser = new WeatherUtil(url); String[] nodes = {"city", "status1" ,"status1", String map = parser.getValue(nodes); //天气信息转换为Map对象 String weather=map. get (nodes[ 0 ])+ " 今天白天:" +map. get (nodes[ 1 ])+ " 最高温度:" +map. get (nodes[ 2 ])+ "℃ 今天夜间:" +map. get (nodes[ 3 ])+ " 最低温度:" +map. get (nodes[ 4 ])+ "℃ " ; //便利数据生成信息字符串 //System.out.println(weather); response.setCharacterEncoding( "utf-8" );response.getWriter().println(weather); //使用AJAX将天气信息返回 session.setAttribute( "weather" , "GBK" ); //定义须要获取天气信息的城市和编码格式 String link= "http://php.weather.sina.com.cn/xml.php?city=" +city_url+ "password=DJOYnieT8234jlsKday=0" ; //气象台接口地址 URL url; //声明地址对象 try {url = new URL(link); //生成url WeatherUtil parser = new WeatherUtil(url); //将url交给工具类处理返回天气信息 String[] nodes = { "city" ,HttpServletResponse response) throws Exception{String city_url = URLEncoder.encode( "昆山" , String map = parser.getValue(nodes); System.out.println(map.get(nodes[0])+" 今天白天:"+map.get(nodes[1])+" 最高温度:"+map.get(nodes[2])+"℃ 今天夜间:"+map.get(nodes[3])+" 最低温度:"+map.get(nodes[4])+"℃ "); } catch (MalformedURLException e) { e.printStackTrace(); } } */ } controller中ajax方法 //天气预报(AJAX) @RequestMapping( "weather" ) public void weather (HttpSession session, String map = new HashMapString,dataType: "text" ,。

String(); // 初始化每一个节点的值为null for ( int i = 0 ; i nodes.length; i++) {map.put(nodes[i], weather); //防止丢失将天气信息同时放入session中 } catch (MalformedURLException e) {e.printStackTrace();}}