Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>HTML CODE</p> <pre><code>&lt;input type=hidden id ="selection" name="selection" value=""&gt; &lt;select name="cate"&gt; &lt;option onclick="document.getElementById('selection').value='h';" value="h"&gt;India&lt;/option&gt; &lt;option onclick="document.getElementById('selection').value='m';" value="m"&gt;USA&lt;/option&gt; &lt;option onclick="document.getElementById('selection').value='c';" value="c"&gt;England&lt;/option&gt; &lt;/select&gt; </code></pre> <p>JSP CODE</p> <pre><code>&lt;% String selected = request.getParameter("selection"); %&gt; </code></pre> <p>Now when you are on the JSP page you have an indication of what the user selected. When you render the element append the <strong>select</strong> attribute to the selected option</p> <p>eg: &lt; option value="h" selected > India &lt; / option ></p> <p><strong>UPDATE</strong> In the place where you display the dropdown you have to do some kind of validation where you need to check the <strong>selection</strong> value and what you are actually printing.</p> <pre><code>if(selected ==null || selected.equals('')){ //do regular printing of the dropdown as you do now }else{ out.print("&lt;select&gt;"); while(rs.next()){ if(rs.getString("VALUE").equals(selected )){ out.print("&lt;option value=\""+rs.getString("VALUE")+"\" SELECTED &gt;"+rs.getString("COUNTRY")+"&lt;/option&gt;"); }else{ out.print("&lt;option value=\""+rs.getString("VALUE")+"\" &gt;"+rs.getString("COUNTRY")+"&lt;/option&gt;"); } } out.print("&lt;/select&gt;"); } </code></pre> <p>PS: The code is written on the fly and could need some exception handling or some typos may exist</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload