É o seguinte galera, fiz um projeto que inicia numa jsp, chama um servlet que executa um método e o servlet chama outra JSP. O problema é que no servlet eu criei uma String resposta, executei um método e chamei a outra JSP. Até ai blza, mas a última JSP não reconhece o parametro String resposta = request.getParameter(“resposta”). Alguém ai pode dar uma ajuda?
Segue o código
Servlet:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String pesquisa = request.getParameter("pesquisaRgmNome");
String tipoPesquisa = request.getParameter("RadioGroup1");
String resposta = "";
PrintWriter out = response.getWriter();
try {
setaAlunos();
if (tipoPesquisa.equals("nome")) {
for (int i = 0; i < alunos.length; i++) {
if (alunos[i][0].equals(pesquisa)) {
resposta += "Nome: " + alunos[i][0] + ", RGM: " + alunos[i][1];
break;
} else if (i == alunos.length - 1) {
resposta += "Aluno não encontrado!";
}
}
response.sendRedirect("respostaAlunos.jsp");
} else {
for (int i = 0; i < alunos.length; i++) {
if (alunos[i][1].equals(pesquisa)) {
resposta += "Nome: " + alunos[i][0] + ", RGM: " + alunos[i][1];
break;
} else if (i == alunos.length - 1) {
resposta += "Aluno não encontrado!";
}
}
response.sendRedirect("respostaAlunos.jsp");
}
Só colei a parte do código que importa. Segue o JSP agora:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page - Pesquisa Alunos (Resposta)</title>
<style type="text/css">
#formata{
text-align:left;
padding-left:300px;
padding-top:100px;
}
</style>
</head>
<body>
<center>
<div id="formata">
Resposta: <br /><br /><%= request.getParameter("resposta");%>
</div>
</center>
</body>
</html>
Sou iniciante em JSP e Servlets ainda, caso encontrem um erro absurdamente noob, peço a compreensão