java - 从jsp调用Web服务

标签 java web-services

我已经成功创建了wsdl。它的url是“http://:/aebis/HelpdeskWebserviceImpl?wsdl”。 现在我想使用这个url来调用jsp中的函数。我使用Jboss作为服务器。 请建议是否有人可以提供帮助。 提前致谢。

最佳答案

这是一个使用 eclipse 的 5 分钟示例

我将使用这个 WSDL 来演示

http://www.webservicex.net/ConvertAcceleration.asmx?WSDL

为您的 JSP 创建动态 java 项目

enter image description here

enter image description here

enter image description here

创建 JSP 和一些后端 java 类

enter image description here

你的 JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<%= new myweb.MyClass().getResult()  %>
</body>
</html>

package myweb;

public class MyClass {

    public String getResult(){
        return null;
    }

    public static void main(String[] args) {

        MyClass c = new MyClass();
        System.out.println(c.getResult());

    }

}

现在创建 WS 客户端。单击/选择项目

enter image description here

右键单击并从给定的 WSDL 创建新的 Web 服务客户端

enter image description here

enter image description here

更改 MyClass 来调用 Web 服务(您也可以先使用类 main 进行测试)

 package myweb;

 import java.rmi.RemoteException;

 import NET.webserviceX.www.AccelerationUnitSoap;
 import NET.webserviceX.www.AccelerationUnitSoapProxy;
 import NET.webserviceX.www.Accelerations;

 public class MyClass {

 public String getResult() throws RemoteException {
      AccelerationUnitSoap a = new AccelerationUnitSoapProxy();
      Accelerations x = Accelerations.decimeterPersquaresecond;
      Accelerations y = Accelerations.centimeterPersquaresecond;
      Object z = a.changeAccelerationUnit(1, x, y);
      return z.toString();
 }

 public static void main(String[] args) throws RemoteException {

      MyClass c = new MyClass();
      System.out.println(c.getResult());

 }

 }

将网络应用添加到您的服务器(如果有的话。如果没有,请创建一个新服务器)

enter image description here

清除服务器(强制其刷新应用程序)并启动它

就在这里。

enter image description here

关于java - 从jsp调用Web服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22811484/

相关文章:

java - 对象数组列表中的 If 语句和循环

java - 为什么不使用所有进口?

javascript - Ajax post to Asmx 中缺少参数

c# - 将字符串数组传递给 webservice 方法

java - 使用 Java 枚举

java - JTextField 和 JTextArea

Java 错误 - 安全异常

android - 在本地主机的 Android 应用程序中使用 Web 服务

asp.net - jQuery Ajax 到 asp.net asmx Web 服务抛出请求格式无效 : application/json

java - Autowiring Spring NullPointerException