The server recieves requests from two clients - Raspberry Pi and Android app, both send requests using HttpURLConnection. I need to pass parameters with theese requests, e.g:
http://192.168.0.10:8080/MyProject/MyServer/rpi/checktask?rpi="rpi"
doing it as:
String requestUrl = "http://192.168.0.10:8080/MyProject/MyServer/rpi";
String query = String.format("/checktask?rpi=%s",
URLEncoder.encode("rpi", "UTF-8"));
URL url = new URL(requestUrl + query);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setRequestProperty("Accept-Charset", "UTF-8");
conn.connect();
The Servlet has annotation:
@WebServlet(name = "MyServer", urlPatterns = { "/MyServer/rpi/*", "/MyServer/app/*"})
But when Servlet gets request as above following happens:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getRequestURI(); // /MyProject/MyServer/rpi/*
String query = request.getQueryString(); // null
String context = request.getContextPath(); // /MyProject
String servlet = request.getServletPath(); // /MyServer/rpi
String info = request.getPathInfo(); // /*
}
Although according to those answers: How to use @WebServlet to accept arguments (in a RESTFul way)? and How come request.getPathInfo() in service method returns null?
it should look like this:
String path = request.getRequestURI(); // /MyProject/MyServer/rpi//checktask?rpi="rpi"
String query = request.getQueryString(); // rpi="rpi"
String context = request.getContextPath(); // /MyProject
String servlet = request.getServletPath(); // /MyServer/rpi
String info = request.getPathInfo(); // /checktask?rpi="rpi"
What am I doing wrong?