java 如何在java中使用webservice从URL(浏览器)调用方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10828425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call method from URL (browser) using webservice in java?
提问by Bhavesh Shah
I am new to web project. So I am learning new things related to it. Yesterday I ask question about how to call method as below. Actually I have a webservice having one WADL file in it. Can I create the object of the class which is running on JBOSS server?
我是网络项目的新手。所以我正在学习与之相关的新事物。昨天我问了有关如何调用方法的问题,如下所示。实际上,我有一个包含一个 WADL 文件的网络服务。 我可以创建在 JBOSS 服务器上运行的类的对象吗?
From that I got one reply that u use wadl2java tool which will consume your Application.wadl file and generate java stubs. You can use these generated java classes to invoke the methods on the object deployed in JBoss server.
从那以后,我得到一个答复,说您使用 wadl2java 工具,该工具将使用您的 Application.wadl 文件并生成 java 存根。您可以使用这些生成的 java 类来调用部署在 JBoss 服务器中的对象上的方法。
Accordingly I generate Java Stub which is interface from WADL using wadl2java. But now I want to access the methods from URL of browser. How can I call it?
因此,我使用 wadl2java 生成了 Java Stub,它是 WADL 的接口。但是现在我想从浏览器的 URL 访问这些方法。我怎么称呼它?
I have tried in this way.... http://localhost:8080/prjname/rest/methodName
我试过这种方法...... http://localhost:8080/prjname/rest/methodName
Is it right way to call method from URL?
从 URL 调用方法是正确的方法吗?
Please advice
请指教
Thanks
谢谢
回答by manurajhada
This is what we call standard URL for web services, there is no automatic generated URLs or fixed or predefined URLs to call them.. you have to define URL structure for your project in codebase, you have to declare base url in your web.xml of project (http://localhost:8080/prjname) and further on your java classes and methods (/rest/methodName) using path annotations.
这就是我们所说的 Web 服务的标准 URL,没有自动生成的 URL 或固定或预定义的 URL 来调用它们......你必须在代码库中为你的项目定义 URL 结构,你必须在你的 web.xml 中声明基本 URL项目 ( http://localhost:8080/prjname) 以及使用路径注释的Java 类和方法 ( /rest/methodName)。