<form action="registerServlet">
<tr>
<td>Gender:</td>
<td><select name="gender" id="gender" required>
<option disabled selected> -- select an option -- </option>
<option value="M">Male</option>
<option value="F">Female</option>
</select></td>
</tr>
</form>
This is the html code in which I have to select the gender of a registering person
Now in the registerServlet
I want get the gender by using getparameter()
code for that is
private char gender;
gender=request.getParameter("gender");
But this is giving an error in eclipse. Can anyone help me how to get a character from the html page
request.getParameter()
returns String. You need to do this:
private String param;
param=request.getParameter("gender");
private char gender;
gender=param.charAt(0);
OR
private char gender;
gender=request.getParameter("gender").charAt(0);
Handle null checks if necessary.