title: Maintain persistent state of <select> statement using servlet
body: <p>I am making a simple web app using servlet and JSP, which have multiple drop down lists in a form tags. Now when I change the value in the drop down and the form is submitted, it changes its value to the default, Now I want the drop down list to maintain its state even after being submitted or keep the last selected value selected after submission.</p>
  
  <p>Below is my jsp code:</p>
  
  <pre><code>&lt;p style="font-weight: bold"&gt;select options&lt;/p&gt;
         &lt;select id="opt" name="selOpt"&gt;
            &lt;option value=""&gt;&lt;/option&gt;
            &lt;option&gt;sel1&lt;/option&gt;
            &lt;option&gt;sel2&lt;/option&gt;
          &lt;/select&gt;
  </code></pre>
  
  <p>and this is how my servlet handle request method is:</p>
  
  <pre><code>public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
  
    HttpSession session = request.getSession(true);
    String selection= req.getParameter("selOpt");
  if(selection.isEmpty()){
  
      /** some logic implemented */
      }else {
      /** logic implemented */
  </code></pre>
  
  <p>Can anyone please help how can I achieve a persistent state of selection in using servlet and jsp? any help would be great.</p>
  
  <p>Thanks!</p>