简体   繁体   English

如何在java web service中调用一个方法?

[英]How to call a method in java web service?

I'm a learner of both java and android programming.我是java和android编程的学习者。 I made a web service of hello world.我做了一个 hello world 的网络服务。 Created a class called HelloWorld.创建了一个名为 HelloWorld 的类。 There is only one method in it like其中只有一种方法,例如

sayHello(){
System.out.println("hello world")
}

Now how should I write a android main activity to invoke this method using http request.现在我应该如何编写一个android主要活动来使用http请求调用这个方法。 what are the prerequisites to use http request.使用http请求的先决条件是什么。 What are the libraries to import.要导入的库是什么。 Should I download any library from any where?我应该从任何地方下载任何库吗? I googled for it.我用谷歌搜索了它。 Many irrelevant results are coming.许多无关紧要的结果即将到来。 I'm not able to comprehend from them.So seeking help here which seemed to be the only option.我无法理解他们。所以在这里寻求帮助似乎是唯一的选择。

Kind answer is appreciated.善意的回答表示赞赏。

The Android platform comes with everything you need to make HTTP requests. Android 平台提供了发出 HTTP 请求所需的一切。 You should take a look at the URLHttpConnection.您应该看看 URLHttpConnection。 Bear in mind, that making an HTTP request is a bit harder then just using this class.请记住,与仅使用此类相比,发出 HTTP 请求要困难一些。 You should think about doing it on a worker thread, so you don't block the UI.您应该考虑在工作线程上执行此操作,以免阻塞 UI。 You should also think about the data transfer protocol you are going to use for your client - server communication and how to process the received responses.您还应该考虑将用于客户端 - 服务器通信的数据传输协议以及如何处理接收到的响应。

I think this can get you started: http://developer.android.com/training/basics/network-ops/connecting.html我认为这可以让你开始: http : //developer.android.com/training/basics/network-ops/connecting.html

When you feel more comfortable with the concept, you can try and use a library for your HTTP request.当您对这个概念感到更舒服时,您可以尝试为您的 HTTP 请求使用一个库。 Here is a useful link: https://developer.android.com/training/volley/index.html这是一个有用的链接: https : //developer.android.com/training/volley/index.html

Only one thing - seems like your web service is not sending any data back to clients, it's just printing to the server standard output, so it is unlikely you see any information sent to your Android app.只有一件事 - 似乎您的 Web 服务没有将任何数据发送回客户端,它只是打印到服务器的标准输出,因此您不太可能看到发送到您的 Android 应用程序的任何信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM