Send data to HTTPservlet in android
This is the servlet code in java ME.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
ArrayList<String> listName = new ArrayList<String>();
ArrayList<Integer> listLongitude = new ArrayList<Integer>();
ArrayList<Integer> listLatitude = new ArrayList<Integer>();
String sLongitude = (String) request.getParameter("x");
String sLatitude = (String) request.getParameter("y");
String path, list, scount;
Integer numLong = null;
Integer numLati = null;
Connection con = null;
String slanje = "";
int limitLeft, limitRight, limitUp, limitDown, icount = 0;
if (sLongitude != null && sLatitude != null) {
try {
numLong = Integer.valueOf(sLongitude);
numLati = Integer.valueOf(sLatitude);
} catch(Exception ex) {}
}
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/bazaprojekt", "projekt2009", "midlet");
limitLeft = numLong - 8;
limitRight = numLong + 8;
limitUp = numLati + 8;
...
How d开发者_JAVA技巧o I send x and y to servlet and receive some string in Android?
Just pass them as request parameters in the query string after the Servlet's URL:
http://example.com/context/servlet?x=123&y=456
.
If you're using the PostMethod you can set them using PostMethod.addParameter.
精彩评论