title: In Jersey REST, how to enter FormParam based on whether another FormParam is empty or not?
body: <p>I have a JSP through which I am POSTing some form parameters to a REST resource service "HandlerAPI.executeQuery".</p>
  
  <p>The JSP for POST request is as follows:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;script src="//code.jquery.com/jquery-1.10.2.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;form id="form1"  action="rest/HandlerAPI" method="post" &gt;
  &lt;select id="type1" name="type1"&gt;
  &lt;option value="Option1"&gt;Option1&lt;/option&gt;
  &lt;option value="Option2"&gt;Option2&lt;/option&gt;
  &lt;option value="Option3"&gt;Option3&lt;/option&gt;
  &lt;option value="Option4"&gt;Option4&lt;/option&gt;
  &lt;option value="Option5"&gt;Option5&lt;/option&gt;
  &lt;/select&gt;
  &lt;p&gt;&lt;p/&gt;
  &lt;fieldset&gt;
  &lt;legend&gt;Enter query or input file:&lt;/legend&gt;
  Enter the query:
  &lt;textarea id="type2" name="type2" cols="50" rows="10"&gt;&lt;/textarea&gt;
  &lt;p&gt;&lt;p/&gt;
  Enter the location of input file:
  &lt;input type="file" id="type3" name="type3"&gt;&lt;/input&gt; 
  &lt;input type="submit" value="Submit"/&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;
  &lt;script&gt;
  $(document).ready(function() {
      $('#type2').keyup(function(e) {
          if($(this).val() != '') {
              $(":file").not(this).attr('disabled','disabled');
          } else {
              $(this).removeAttr('disabled');
              $(":file").removeAttr('disabled');
          }
      });
      $(":file").change(function(e) {
          var files = e.target.files;
          if($(":file").val() != '') {
              $("#type2").not(this).attr('disabled','disabled');
          } else {
              $(":file").removeAttr('disabled');
              $("#type2").removeAttr('disabled');
          }
      });
  });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The resource service method is as follows:</p>
  
  <pre><code>@Path("/HandlerAPI")
  public class HandlerAPI extends PackagesResourceConfig {
      ...
  @POST
  @Path("/{type1}/({type2}|{type3})")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.TEXT_PLAIN)
  
  public String executeQuery(@FormParam("type1") String type1, @FormParam("type2") String type2, @FormParam("type3") String type3) {
      //service implemented here
  return "Query successfully executed.";
  </code></pre>
  
  <p>}</p>
  
  <p>My requirement is that:</p>
  
  <ol>
  <li>"type3" FormParam will be passed to the service method if "type2"
  FormParam is empty </li>
  <li>"type3" FormParam will not be passed to the service method if "type2" FormParam is non-empty</li>
  </ol>
  
  <p>Accordingly my annotated @Path url is going to be adjusted. </p>
  
  <p>Any helpful suggestion will be appreciated and rewarded.</p>
  
  <p>Thanks </p>