繁体   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