Hello, I am going to do a few exercises from the university for the java programming class.
What I have to do in this is a login, then I enter the user and a password, which go in 2 text boxes that are in a jsp, by clicking the button sends the data to a servlet that validates and sends the response again to the eye (jsp), which has to come out by means of an alert on the screen to the user.
My code is like this:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LOGIN</title>
</head>
<body>
<div align="center">
<h1>LOGIN</h1>
<h4>Ingrese los datos que se solicitan: </h4>
<!-- este es el form que se encarga de encapsular los textbox y los botones, este manda la informacion de estos al servlet -->
<form name="idLogin" action="srvLogin" method="POST">
<input type="text" name="txtUsuario" value="" placeholder="NOMBRE DE USUARIO"/><br><br>
<input type="text" name="txtPass" value="" placeholder="CONTRASEÑA"/><br><br>
<input type="submit" value="Calcular" name="btnlog" /> <!-- este es el boton que desencadena el evento-->
</form>
<% //si ls respuesta de mi servlet es diferente a vacio
if(request.getAttribute("mensaje")!=null)
{ //tendrìa que mandar a imprimir por medio del alert de abajo el mensaje de acceso correcto o incorrecto, pero no me lo muestra
%>
<script>alert( "Hola " + <%=request.getAttribute("mensaje")%>) </script>
<br>
<!-- este es una caja de texto que puse para ver si estaba conectando correctamente al servlet y si conecta pero no muestra el alert-->
<input type="text" name="txtResultado" value="<%=request.getAttribute("mensaje")%>" disabled/>
<%
}
%>
</div>
</body>
In other words, if it shows everything right, it makes the connection with the servlet and validates and returns the response, however I have a problem with the alert when executing it does not appear, it only shows me the input below the alert that I put it to verify If I made the connection or not, and I see that the problem is in the alert, I have bad syntax of the alert? Thanks again!