我们使用 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>
但这不起作用。请帮忙,