Quero saber como pegar parametros vindo do arquivo .jsp no meu controller (servlet). O servlet selecionou uma das opçes e mandou abrir um arquivo .jsp que exibe um formulário. Meu código é no controller (servlet) assim:
String optionRecord = request.getParameter( “record” );
if(optionRecord.compareTo("add") == 0){
RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/addData.jsp");
dispatcher.include(request, response);
}
else {
//db.getColumnHeaders();
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/searcData.jsp");
dispatcher.include(request, response);
}
// Receive the request from JSP to send to model
String[] paramValues = request.getParameterValues("selectData");
String string = "select ";
for(int i = 0; i < paramValues.length; i++){
System.out.println(paramValues[i] + "\t");
}
um dos arquivos .jsp é como:
<tr>
<td> SELECT </td>
<td> <input type = "checkbox" name = "selectData" value="memberID" checked/>MemberID</td>
</tr>
<tr>
<td> </td>
<td> <input type = "checkbox" name = "selectData" value="firstName" checked/>FirstName</td>
</tr>
<tr>
<td> WHERE </td>
<td> <input type = "text" name = "where" size="25" maxlength="80"/></td>
</tr>
<tr>
<td> ORDER BY </td>
<td> <input type = "radio" name = "orderBy" value="memberID" checked/>MemberID</td>
</tr>
<tr>
<td> </td>
<td> <input type = "radio" name = "orderBy" value="firstName"/>FirstName</td>
</tr>
<tr>
<td> ASC/DSC </td>
<td> <input type = "radio" name = "ascDsc" value="asc" checked/>ASC</td>
</tr>
<tr>
<td> </td>
<td> <input type = "radio" name = "ascDsc" value="dsc"/>DSC</td>
</tr>
<tr>
<td> </td>
<td><input type ="submit" name = "Submit" value="Search Record"/></td>
</tr>
</table>
</form>
String optionRecord = request.getParameter(“record”); deterimine que açâo deeve ser feita. Depois envia isso a uma pagina .jsp para selecionar os elementos a colocar no string do SELECT que o servlet pega para mandar no banco de dados. A situaçâo é como: