0
我正在開發用於天氣預報的Android應用程序。目前我已經在servlet中編寫了服務器端代碼。 我的網絡服務器是Apache Tomcat。我如何在web服務器上部署我的servlet?什麼是部署servlet的步驟。謝謝你提前。在Web服務器上部署servlet
package com.example.WeatherDetails;
import com.example.Info.INFORMATION;
import com.example.Info.WeatherInformation;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public class WeatherDetails extends HttpServlet
{
public WeatherDetails()
{
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request,response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String LAT = request.getParameter("LAT");
String LONGITUDE = request.getParameter("LONGITUDE");
PrintWriter out = response.getWriter();
//get list of countries
WeatherInformation WeatherInformation = new WeatherInformation();
ArrayList<INFORMATION> WeatherInfo = WeatherInformation.getList(LAT,LONGITUDE);
Gson gson = new Gson();
JsonArray arrayObj=new JsonArray();
for(int i=0;i<WeatherInfo.size();i++)
{
INFORMATION information = WeatherInfo.get(i);
JsonElement productObj = gson.toJsonTree(information);
arrayObj.add(productObj);
}
//create a new JSON object
JsonObject myObj = new JsonObject();
//add property as success
myObj.addProperty("success", true);
//add the countryList object
myObj.add("WeatherInfo", arrayObj);
//convert the JSON to string and send back
out.println(myObj.toString());
out.close();
}
}
謝謝你的回答,但我想在網絡服務器上部署它。在本地主機上它工作得很好。 – 2014-08-28 15:29:49