title: Java- Servlet - redirecting request with a new body
body: <p>I'm writing a Servlet in Java, that basically, gets a request with a XML in the Requests body, and then changes a few things in the XML and redirect/foreword the request with The new XML to a different Servlet that's on the same server, but its  on a different web app.</p>
  
  <p>I'm using doPost.</p>
  
  <p>How do i do that? can i find code example any where?</p>
  
  <p>Plus, whats the correct method to use:?</p>
  
  <p><code>request.getRequestDispatcher().include /request.getRequestDispatcher().foreword / response.sendRedirect()</code>  or  do i need to use the: <code>HttpServletRequestWrapper</code>?</p>
  
  <p>this is what i have so far:</p>
  
  <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
       String body = getBody(request);
       MapXml mapXml = new MapXml(body, "C:\\Projects\\XmlMapper\\output.xml","C:\\Projects\\XmlMapper\\output\\");
       String outputXml = mapXml.getOutputXml();
  
  
  
  }
  public static String getBody(HttpServletRequest request) throws IOException {
  
      String body = null;
      StringBuilder stringBuilder = new StringBuilder();
      BufferedReader bufferedReader = null;
  
      try {
          InputStream inputStream = request.getInputStream();
          if (inputStream != null) {
              bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
              char[] charBuffer = new char[128];
              int bytesRead = -1;
              while ((bytesRead = bufferedReader.read(charBuffer)) &gt; 0) {
                  stringBuilder.append(charBuffer, 0, bytesRead);
              }
          } else {
              stringBuilder.append("");
          }
      } catch (IOException ex) {
          throw ex;
      } finally {
          if (bufferedReader != null) {
              try {
                  bufferedReader.close();
              } catch (IOException ex) {
                  throw ex;
              }
          }
      }
  
      body = stringBuilder.toString();
      return body;
  }
  </code></pre>
  
  <p>And i have no idea how to continue on from here. I'm new to the servlet world..
  Thanks!!!
  <strong>Cheers:)</strong></p>