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.
Below is my jsp code:
<p style="font-weight: bold">select options</p>
<select id="opt" name="selOpt">
<option value=""></option>
<option>sel1</option>
<option>sel2</option>
</select>
and this is how my servlet handle request method is:
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 */
Can anyone please help how can I achieve a persistent state of selection in using servlet and jsp? any help would be great.
Thanks!