title: How to get query parameters from HttpServletRequest (Tomcat 9.0)?
body: <p>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:</p>
  
  <pre><code>http://192.168.0.10:8080/MyProject/MyServer/rpi/checktask?rpi="rpi"
  </code></pre>
  
  <p>doing it as:</p>
  
  <pre><code>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();
  </code></pre>
  
  <p>The Servlet has annotation:</p>
  
  <pre><code>@WebServlet(name = "MyServer", urlPatterns = { "/MyServer/rpi/*", "/MyServer/app/*"})
  </code></pre>
  
  <p>But when Servlet gets request as above following happens:</p>
  
  <pre><code>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();       // /*
  }
  </code></pre>
  
  <p>Although according to those answers:
  <a href="https://stackoverflow.com/questions/31322586/how-to-use-webservlet-to-accept-arguments-in-a-restful-way">How to use @WebServlet to accept arguments (in a RESTFul way)?</a>
  and
  <a href="https://stackoverflow.com/questions/3745275/how-come-request-getpathinfo-in-service-method-returns-null">How come request.getPathInfo() in service method returns null?</a></p>
  
  <p>it should look like this:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>What am I doing wrong? </p>