title: How to determine if a parameter has been "posted" or "geted" from Java?
body: <p>In ASP, there's <code>request.form</code> and <code>request.queryString</code> attributes, but in Java. It seems like we have only one collection, which can be accessed via <code>request.getParamaterMap</code>, <code>getParametersNames</code>, <code>getParameterValues</code> etc.</p>
  
  <p>Is there some way to tell which values have been posted and which ones have been specified in the URL?</p>
  
  <hr>
  
  <p>PS: </p>
  
  <p>What I'm trying to achieve is to make a page that can handle the following situation</p>
  
  <ul>
  <li>Read the variables that came from the querystring (get)</li>
  <li>Read a single post with a certain name ( "xml", for example ).</li>
  <li>If that post is missing, read the whole body (with the
  <code>request.getReader()</code>).</li>
  </ul>
  
  <p>I'm using tomcat 6.</p>
  
  <p>According to what I've seen so far, if I issue a <code>request.getReader()</code>, posted values no longer appears in the <code>getParamater</code> collection, nevertheless querystring parameters are still there.</p>
  
  <p>On the other hand, if I issue any of the <code>getParameters</code> methods, <code>getReader</code> returns empty string.</p>
  
  <p>Seems like I can't have the cake and eat it too.</p>
  
  <p>so, I guess the solution is the folowwing:</p>
  
  <ul>
  <li>Read the body with <code>getReader</code>.</li>
  <li>See if the xml post is there (downside, I have to manually parse the body.</li>
  <li>If it is, get the http message body and get rid of the "xml=" part.</li>
  <li>If it's not, well, just get the body.</li>
  <li>Read the querystring parameters through <code>request.getParameter</code></li>
  </ul>
  
  <p>Any better idea?</p>
  
  <ul>
  <li>PS: Does anybody knows how to parse the body using the same method
  used by <code>HttpServlet</code>?</li>
  <li>PS: <a href="http://www.aspnut.com/reference/encoding.asp" rel="noreferrer">Here</a> is a decoding ASP function. Shall I just rewrite it in
  Java?</li>
  <li>PS: Also <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLDecoder.html" rel="noreferrer">found</a> (don't have a machine to test it right now)</li>
  </ul>
  
  <p>Just to clarify things. The problem seems to be that with <code>getParameter</code> you get posted values as well as values passed with the URL, consider the following example:</p>
  
  <pre><code>&lt;%@page import="java.util.*"%&gt;
  &lt;%
    Integer i;
    String name;
    String [] values;
  
    for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
  
      name = (String) e.nextElement();
      values = request.getParameterValues( name );
  
      for ( i=0; i &lt; values.length; i ++ ) {
        out.println( name + ":" + values[i] + "&lt;br/&gt;" );
      }
    }
  %&gt;
  
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;param test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form method="post" action="http://localhost:8080/jsp_debug/param_test.jsp?data=from_get"&gt;
      &lt;input type="text" name="data" value="from_post"&gt;
      &lt;input type="submit" value="ok"&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>the output of this code is</p>
  
  <pre><code>data:from_get
  data:from_post
  
  ...
  </code></pre>
  
  <p>Seems like in order to find which parameter came from where, I have to check <code>request.getQueryString</code>.</p>