[英]Webservice - how to deploy?
I am trying to write a simple webservice which produces a JSON string. 我正在尝试编写一个生成JSON字符串的简单Web服务。 What I really want to do is get some info from my database through this JSON string and use it in my Android application. 我真正想做的是通过此JSON字符串从数据库中获取一些信息,并在我的Android应用程序中使用它。 I want to write it all in Java and try to avoid using php. 我想用Java编写所有内容,并尝试避免使用php。
I am not sure how to deploy this thing to my remote server through Filezilla. 我不确定如何通过Filezilla将其部署到我的远程服务器上。
This is just not the end result at all. 这根本不是最终结果。 I just tried to write something that could produce a JSON string. 我只是试图写一些可能产生JSON字符串的东西。 I am using the jersey lib btw. 我正在使用jersey lib btw。
package services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import org.json.JSONException;
import org.json.JSONObject;
@Path("/webservice")
public class RestFulWebservice {
@GET
@Produces("application/json")
public Response produceJSON() throws JSONException {
JSONObject jsonObject = new JSONObject();
double weight = 62;
double height = 170;
jsonObject.put("Weight", weight);
jsonObject.put("Height", height);
String result = "Produces JSON: \n" + jsonObject;
return Response.status(200).entity(result).build();
}
}
I would really appreciate any advice. 我真的很感谢任何建议。 If I can just produce a dynamic JSON string I think I know how to read in my code. 如果我只能产生一个动态JSON字符串,我想我知道如何读取我的代码。
打扰一下,但我不明白Java代码接收到JSON对象还是Java代码发送了JSON对象。
Deploying Java applications on the server is not like in PHP where you just copy files. 在服务器上部署Java应用程序与仅复制文件的PHP不同。 You need to build a WAR (web archive) package and deploy it in a servlet container, for example Tomcat . 您需要构建一个WAR(Web归档文件)包并将其部署在servlet容器中,例如Tomcat 。
Your code needs to run in a webcontainer of some sort (tomcat, jetty etc). 您的代码需要在某种Web容器(tomcat,码头等)中运行。
You have a couple of options, either a separately installed webcontainer or one embeddded in your application. 您有两种选择,要么是单独安装的Web容器,要么是嵌入在应用程序中的一个。
You then need to build your compiled code into a war (to deploy to a separately installed container) or an executable jar (for an embedded container). 然后,您需要将编译后的代码构建到war中(以部署到单独安装的容器中)或可执行jar(用于嵌入式容器)中。
If you're just getting started with web containers then its probably best to read up on something like tomcat. 如果您只是开始使用Web容器,那么最好阅读有关tomcat之类的内容。
Alternatively you can look at something like spring boot. 或者,您可以查看类似弹簧靴的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.