Issue
my problem is that i have two lists in my jsp and they both need to be selected. The problem is that when they are both selected at the same time it gives my sth like this: String userType = request.getParameter("userType"); -> return selected value
String uBranch = request.getParameter("uBranch"); -> return null
here is JSP code:
<tr>
<td><label>Branch </label></td>
<td>
<form action="EmployeeControllerServlet">
<select name="uBranch">
<option value="${loadedEmployee.branch}"></option>
<option value="IT">IT</option>
<option value="ACC">ACC</option>
<option value="HR">HR</option>
</select>
</form>
</td>
</tr>
<tr>
<td><label>Privilege </label></td>
<%--<td><input type="text" name="uPrivilege" value="${loadedEmployee.userType}"></td>--%>
<td>
<form action="EmployeeControllerServlet">
<select name="userType">
<option value="${loadedEmployee.userType}"></option>
<option value="regular">REGULAR</option>
<option value="admin">ADMIN</option>
</select>
</form>
</td>
</tr>
SERVLET
private void updateUserInfo(HttpServletRequest request, HttpServletResponse response) {
try {
String firstName = request.getParameter("ufirstname");
String secondName = request.getParameter("usecondname");
String lastName = request.getParameter("ulastUName");
String dateOfBirth = request.getParameter("udateOfBirth");
String dateOfJoin = request.getParameter("udateOfJoin");
String userName = request.getParameter("uName");
String userPass = request.getParameter("uPassword");
String uMail = request.getParameter("ueMail");
String userType = request.getParameter("userType");
String uBranch = request.getParameter("uBranch");
String id = request.getParameter("employeeId");
System.out.println(uBranch + " branch");
System.out.println(userType + " type");
Dao.getInstance().updateSelectedUser(userName,userPass,uMail,userType,firstName,secondName,
lastName,dateOfBirth,dateOfJoin,uBranch,id);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Solution
The reason is that you have using two form
called EmployeeControllerServlet
at the same time,so only the last form work,thus you can only get data from userType
.
To solve this,you need to merge the two form
into one form
,one possible way is make form outside table,as below:
<form action="EmployeeControllerServlet"> <!-- only use one form -->
<table>
<tbody>
<tr>
<td><label>Branch </label></td>
<td>
<select name="uBranch">
<option value="${loadedEmployee.branch}"></option>
<option value="IT">IT</option>
<option value="ACC">ACC</option>
<option value="HR">HR</option>
</select>
</td>
</tr>
<tr>
<td><label>Privilege </label></td>
<td>
<select name="userType">
<option value="${loadedEmployee.userType}"></option>
<option value="regular">REGULAR</option>
<option value="admin">ADMIN</option>
</select>
</td>
</tr>
</table>
</tbody>
</form>
Answered By - lucumt
Answer Checked By - Senaida (JavaFixing Volunteer)