I want to send this url from an android class to my servlet. I have written the code for servlet where it catches the values of parameter but I am not able to send this url. What is the code to do this?
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
URL url;
try {
URL url = new URL("http://localhost:8080/ExtraServ/AssessmentServlet?param1="+lat+lng);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
My servlet code:
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
final String par1 = req.getParameter("param1");
final String par2 = req.getParameter("param2");
FileWriter fstream = new FileWriter("C:\\Users\\Hitchhiker\\Desktop\\out2.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(par1);
out.append(" ");
out.append(par2);
out.close();
localhost will be your own device (127.0.0.1).
you’ll have to choose your servlet’s ip and be connected to the same network.
the connection part is missing in your code: