title: which is best way to map servlet request parameters to a java class?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5096454/easy-way-of-populating-javabeans-based-on-request-parameters">Easy way of populating Javabeans based on request parameters</a>  </p>
  </blockquote>
  
  
  
  <p>Hi, </p>
  
  <p>I have a Java Object with a set of search parameters, sth. like </p>
  
  <pre><code>public class SearchRequest {
  
  private String customerName;
  private String city;
  ...
  }
  </code></pre>
  
  <p>This request has to be filled by a servet request.</p>
  
  <p>But instead of writing code like</p>
  
  <p>...</p>
  
  <pre><code>SearchRequest searchRequest = new SearchRequest();
  
  if (request.getParameter("customerName") != null)
  { 
      searchRequest.setCustomerName(request.getParameter("customerName"));
  }
  if (request.getParameter("city") != null)
  { 
      searchRequest.setCity(request.getParameter("city"));
  }
  </code></pre>
  
  <p>...
  I'm looking for a more generic way.</p>
  
  <p>I was checking the mapping tool Dozer but did not find a nice way how to handle this mapping.</p>
  
  <p>Now I think reflection would be a choice.
  Is this true? 
  If so does anyone has a code sniplet how this can be done with reflection?</p>