簡體   English   中英

從html調用Web服務

[英]calling web service from html

我們已經創建了用於使用Netbeans進行溫度轉換的Web服務。 一切正常。

@WebMethod(operationName = "tempConverter")
public Double tempConverter(@WebParam(name = "temp") double temp, 
                            @WebParam(name = "choice") int choice) {
    switch(choice)
    {
        case 1:
        tempConv =  (9.0/5.0)*(ip)+32.0;
        break;

        case 2:
        tempConv = (5.0/9.0)*(ip-32.0);
        break;
     }
     return tempConv;
}

但是我們想在html中使用此Web服務。 chanService是Web服務的名稱。

的代碼是:

<script language="javascript">
            function initialize()
            {
                service.useService("http://localhost:8080/chanService/chanService.java?WSDL","tempConverterService");
            }

            function getTemp()
            {
                var temp,choice;
                temp=document.getElementById('temp').value;
                choice=document.getElementById('choice').value;
                service.tempConverterService.callService(tempConverter,temp,choice);

            }
            function Result() 
{ 
alert(event.result.value); 
} 


        </script>

    </head> 
    <body onload="initialize()" id="service" onresult="Result()">
        <form name="form1">
            <input type="text" name="temp" id="temp" value="0" size="50" />
            <input type="text" name="choice" value="1" id="choice" size="50" />
            <input type="button" value="Submit" name="submit" onclick="getTemp()"/>
        </form>

但這是行不通的。 請幫忙,

您需要在body標簽中添加style =“ behavior:url(webservice.htc)”並將文件放置在頁面的同一文件夾中。

看到這個http://msdn.microsoft.com/en-us/library/ie/ms531063(v=vs.85).aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM