導航:首頁 > 編程語言 > 天氣預報webservicejava

天氣預報webservicejava

發布時間:2022-08-12 13:56:34

⑴ 在調用天氣預報webservice時出現java.io.IOException: Server returned HTTP response code:400

如果是要調用webservice的話,JS很難實現,因為webservice的客戶端有很多JAR包的,除非用JS模擬JAVA的中的webservice調用。
其實你可以到網上找一個天氣預報的頁面,然後直接在頁面上嵌套一個iframe,或者用AJAX獲取response,然後通過document.getElementById('xx').innerHTML = '得到的response字元串';的方式來實現。
GOOD LUCK!

⑵ java實現對天氣查詢的webservice的查詢客戶端

會調用webservice嗎?會的話,我給你個查詢天氣的webservice地址
天氣預報Web服務,數據來源於中國氣象局
Endpoint :http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
Disco :http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?disco
WSDL :http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
如果你不會webservice,可以先學習下

⑶ 如何使用java webservice調用第三方天氣

請參考以下代碼:

public static void WeatherTest(){

try {

String endpoint = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl";
Service service = new Service();
Call call = (Call)service.createCall();// 通過service創建call對象

// 設置service所在URL

call.setTargetEndpointAddress(new java.net.URL(endpoint));

call.setOperationName(new QName("http://WebXml.com.cn/", "getWeatherbyCityName"));
call.addParameter(new QName("http://WebXml.com.cn/","theCityName"),org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

call.setUseSOAPAction(true);

call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR); //返回參數的類型(不能用Array,否則報錯)

call.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");

Vector ret = (Vector) call.invoke(new Object[]{"大慶"});

System.out.println("--------"+ret);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

⑷ java web service實現天氣預報功能

前台js界面代碼:

//省份
functionLoadProvince(){
$.ajax({
type:"POST",
url:"ashx/weatherHandler.ashx",
data:"option=province",
success:function(result){
$(".sel-provinceoption").remove();
vararry=result.split('|');
varobj=null;
for(vari=0;i<arry.length;i++){
if(arry[i]!=null&&arry[i]!=""){
obj=arry[i].split(',');
$(".sel-province").append("<optionvalue='"+obj[1]+"'>"+obj[0]+"</option>");
}
}
$(".sel-province").find("option[text='北京']").attr("selected","selected");
},
error:function(errorMsg){
$(".result-tabletr").remove();
$(".result-table").append("<tr><td>省份請求出現錯誤,請您稍後重試。。。</td></tr>");
}
});
}
//城市
functionLoadCity(provinceid){
$.ajax({
type:"POST",
url:"ashx/weatherHandler.ashx",
data:"provinceid="+provinceid+"&option=city",
success:function(result){
$(".sel-cityoption").remove();
vararry=result.split('|');
varobj=null;
for(vari=0;i<arry.length;i++){
if(arry[i]!=null&&arry[i]!=""){
obj=arry[i].split(',');
$(".sel-city").append("<optionvalue='"+obj[1]+"'>"+obj[0]+"</option>");
}
}
},
error:function(errorMsg){
$(".result-tabletr").remove();
$(".result-table").append("<tr><td>城市請求出現錯誤,請您稍後重試。。。</td></tr>");
}
});
}
//載入天氣
functionGetWeather(cityid){
$.ajax({
type:"POST",
url:"ashx/weatherHandler.ashx",
data:"cityid="+cityid+"&option=weather",
success:function(result){
$(".result-tabletr").remove();
vararry=result.split('|');
varobj=null;
for(vari=0;i<arry.length;i++){
if(arry[i]!=null&&arry[i]!=""){
if(arry[i].indexOf(".gif")>0){
$(".result-table").append("<tr><td><imagesrc='images/"+arry[i]+"'/></td></tr>");
}
else{
$(".result-table").append("<tr><td>"+arry[i]+"</td></tr>");
}
}
}
},
error:function(errorMsg){
$(".result-tabletr").remove();
$(".result-table").append("<tr><td>天氣數據請求出現錯誤,請您稍後重試。。。</td></tr>");
}
});
}

html代碼:

<body>
<formid="form1"runat="server">
<divclass="head-div">
<table>
<tr>
<td>
<selectclass="sel-provincesel">
</select>
</td>
<td>
<selectclass="sel-citysel">
</select>
</td>
<td>
<inputtype="button"class="btn-search"value="查詢"/>
</td>
</tr>
</table>
</div>
<divclass="result-div">
<tableclass="result-table">
</table>
</div>
</form>
</body>

由於js不支持跨域,直接ajax+ashx一般處理程序(在裡面調用天氣介面)。一般處理程序代碼如下:

usingSystem.Web;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Text;

namespaceWeatherTest.ashx
{
///<summary>
///weatherHandler的摘要說明
///</summary>
publicclassweatherHandler:IHttpHandler
{
WeatherWsClient.WeatherWSSoapClientclient=newWeatherWsClient.WeatherWSSoapClient();
publicvoidProcessRequest(HttpContextcontext)
{
context.Response.ContentType="text/plain";
string[]result=null;
stringoption=context.Request.Form["option"];
switch(option)
{
case"province":
result=GetProvinces();
break;
case"city":
result=GetCitys(context.Request.Form["provinceid"]);
break;
case"weather":
result=GetWeather(context.Request.Form["cityid"],null);
break;
}
stringstr=ConvertToString(result,option);

context.Response.Write(str);
}
///<summary>
///數組轉字元串
///</summary>
///<paramname="result"></param>
///<paramname="option"></param>
///<returns></returns>
privatestringConvertToString(string[]result,stringoption)
{
StringBuildersb=newStringBuilder();
foreach(stringiteminresult)
{
sb.Append(item+"|");
}
returnsb.ToString();
}

///<summary>
///省份
///</summary>
///<returns></returns>
privatestring[]GetProvinces()
{
returnclient.getRegionProvince();
}
///<summary>
///城市
///</summary>
///<paramname="provinceid"></param>
///<returns></returns>
privatestring[]GetCitys(stringprovinceid)
{
returnclient.getSupportCityString(provinceid);
}
///<summary>
///天氣數據
///</summary>
///<paramname="cityid"></param>
///<paramname="userid"></param>
///<returns></returns>
privatestring[]GetWeather(stringcityid,stringuserid)
{
returnclient.getWeather(cityid,userid);
}

publicboolIsReusable
{
get
{
returnfalse;
}
}
}
}

⑸ 根據以往天氣狀況表中數據編寫預測以後天氣的java程序

用HttpClient調用天氣預的url,看一下網上API返回的格式,用JSON封裝一下就行了;天氣預報一般都是通過webservice來調用的多些。

⑹ 如何獲取天氣預報的wsdl

1、天氣預報web services地址
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
用瀏覽器打開此地址,保存頁面為Weather.xml
2、新建一個java工程 webservices
建立包名 com.test.ws
將Weather.xml拷貝到src目錄下
3、編寫批處理WSDL-SQUARED.CMD,使用wsdj2java生成客戶端調用代碼

setAXIS_HOME=D:axis-1_4
setCLASSPATH=.;%AXIS_HOME%libaxis.jar;%AXIS_HOME%libaxis-ant.jar;%AXIS_HOME%libcommons-discovery-0.2.jar;%AXIS_HOME%libcommons-logging-1.0.4.jar;%AXIS_HOME%libjaxrpc.jar;%AXIS_HOME%liblog4j-1.2.8.jar;%AXIS_HOME%libsaaj.jar;%AXIS_HOME%libwsdl4j-1.5.1.jar
javaorg.apache.axis.wsdl.WSDL2Java-pcom.test.wsWeather.xml

⑺ 誰知道如何在Java中使用天氣預報這個東西,用在自己的網站中,而且可以在自己的網站中查詢天氣,

做軟體的人都不喜歡發明重復的輪子,天氣那種情況是用的webservice技術解決的,通過SOAP協議,必須天氣預報那個項目那面提供給你一個介面才可以,還需要提供給你wsdl文件。 如果想自己實現,那你自己得做一個那樣的功能。 webservice好處就在於在不同語言中獲取』行為『,因為他是通過xml文件傳遞數據。

⑻ 怎樣從國家氣象局天氣預報獲取java

你沒有介面使用許可權啊,我記得有個公共免費的天氣預報的webservice,可以用java調用,不知道那是不是氣象局的

閱讀全文

與天氣預報webservicejava相關的資料

熱點內容
如何把掃描文件做成pdf格式 瀏覽:624
php個性qq源碼 瀏覽:821
初學c語言顯示源未編譯 瀏覽:245
資產概況源碼 瀏覽:472
dos命令建文件夾命令 瀏覽:379
解壓的密碼htm被屏蔽 瀏覽:502
冬天太冷冰箱壓縮機不啟動怎麼辦 瀏覽:83
手機打開vcf需要什麼編譯器 瀏覽:910
加密磁碟後開機很慢 瀏覽:271
長沙智能雲控系統源碼 瀏覽:258
阿里雲伺服器如何設置操作系統 瀏覽:999
超級命令的英文 瀏覽:784
做賬為什麼要用加密狗 瀏覽:586
考研群體怎麼解壓 瀏覽:159
linux修改命令提示符 瀏覽:226
圓圈裡面k圖標是什麼app 瀏覽:63
pdf加空白頁 瀏覽:948
linux伺服器如何看網卡狀態 瀏覽:318
解壓新奇特視頻 瀏覽:707
圖書信息管理系統java 瀏覽:554