I have a problem in the request.getRequestDispatcher ("Valida.jsp"). forward (request, response); from my servlet that does not forward to the Valida.jsp page. I need to pass from an HTML to a javascript (by Ajax) which passes the infos to a Servlet and that servlet writes the data in a JavaBeans and from the foward to a jsp show the data. It does not give any console or compilation error. It just stands in the main html page.
My Servlet looks like this:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Beans beans = new Beans();
String email = request.getParameter("email");
String senha = request.getParameter("senha");
String Pnome= request.getParameter("Pnome");
String Mnome= request.getParameter("Mnome");
String Snome= request.getParameter("Snome");
beans.setEmail(email);
beans.setSenha(senha);
beans.setPnome(Pnome);
beans.setMnome(Mnome);
beans.setSnome(Snome);
request.setAttribute("beans", beans);
request.getRequestDispatcher("Valida.jsp").forward(request, response);
System.out.println("passou do forward");
}
My JAVASCRIPT
count = 0;
onload = inicia;
function inicia() {
document.getElementById("idCadastra").addEventListener("click", conecta, false);
}
function conecta() {
var email = document.getElementById("idEmail").value;
var senha = document.getElementById("idSenha").value;
var Pnome = document.getElementById("idPrimeiroNome").value;
var Mnome = document.getElementById("idNomeDoMeio").value;
var Snome = document.getElementById("idSobreNome").value;
if (email != "" && senha != "" && Pnome != "" && Snome != "") {
console.log("entrou na conexão")
httpRequest = createRequest();
httpRequest.open("GET", "Servlet?email=" + email + "&senha=" + senha + "&Pnome=" + Pnome + "&Mnome=" + Mnome + "&Snome=" + Snome, true);
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
}
}
}
httpRequest.send(null);
}
}
-------MEU HTML-------
<td class="td" align="right" width="300">
Ainda não é usuário? Crie o seu Login:
<form method="get">
e-mail:
<input id="idEmail" type="text" name="e-mail" required="required">*
<br>Senha:
<input id="idSenha" type="text" name="senha" required="required">*
<br>Repita Senha:
<input id="idRepitaSenha" type="text" name="repitasenha" required="required">*
<br>Primeiro Nome:
<input id="idPrimeiroNome" type="text" name="primeironome" required="required">*
<br>Nome do Meio:
<input id="idNomeDoMeio" type="text" name="nomedomeio">  
<br>Sobrenome:
<input id="idSobreNome" type="text" name="sobrenome" required="required">*
<br>
</form>
<button class="inputCriarLogin" id="idCadastra" name="criarlogin">Criar Login</button>