HTMLコード
<input type=hidden id ="selection" name="selection" value="">
<select name="cate">
<option onclick="document.getElementById('selection').value='h';" value="h">India</option>
<option onclick="document.getElementById('selection').value='m';" value="m">USA</option>
<option onclick="document.getElementById('selection').value='c';" value="c">England</option>
</select>
JSPコード
<%
String selected = request.getParameter("selection");
%>
これで、JSPページを表示しているときに、ユーザーが何を選択したかがわかります。要素をレンダリングするときに、選択したオプションにselect属性を追加します
例:<option value="h"が選択されました>インド</option>
更新ドロップダウンを表示する場所で、選択値と実際に印刷しているもの
を確認する必要がある、ある種の検証を行う必要があります。
if(selected ==null || selected.equals('')){
//do regular printing of the dropdown as you do now
}else{
out.print("<select>");
while(rs.next()){
if(rs.getString("VALUE").equals(selected )){
out.print("<option value=\""+rs.getString("VALUE")+"\" SELECTED >"+rs.getString("COUNTRY")+"</option>");
}else{
out.print("<option value=\""+rs.getString("VALUE")+"\" >"+rs.getString("COUNTRY")+"</option>");
}
}
out.print("</select>");
}
PS:コードはオンザフライで記述されており、例外処理が必要になるか、タイプミスが存在する可能性があります