Olá pessoal, Estou com problemas no uso de dados manipulados em um Function (). Minha HTML (vejam abaixo) mostra a tela normalmente. Quando eu clico no botão o Servlet é chamado corretamente e retorna um texto. A function é chamada (onclick) e usando o texto retornado pelo Servlet ela seleciona a mensagem q deve ser mostrada. Até aí tudo ok. O problema está na demonstração dessa mensagem que é montada no id=“wMsga”. A mensagem aparece por 1 segundo (como um flash) e logo depois some. Já o id=“wMsg” q fica na linha anterior a da mensagem mostra corretamente o texto recebido do Servlet.
Segue a HTML:
<!DOCTYPE html>
<html lang ="pt-br">
<head>
<title> loginServlet2 </title>
<meta http-equiv = ”Content-Type” content=”text/html; charset=UTF-8”>
<link rel="stylesheet" type="text/css" href="c:/java/html/css/estilo.css"/>
<script>
function oMsg()
{
var wMsg1 = document.getElementById('wMsg').innerHTML;
if (wMsg1 == "Teste OK!")
{
document.getElementById('wMsga').innerHTML="Recebi Teste OK";
}
else
{
document.getElementById('wMsga').innerHTML="Não Recebi Teste OK";
}
}
</script>
</head>
<body>
<h2> Login Page2 </h2>
<p>Please enter your username and password</p>
<form method="GET" action="loginServlet2">
<p> Username <input type="text" name="userName" size="50"> </p>
<p> Password <input type="text" name="password" size="20"> </p>
<p> <input type="submit" value="Submit" name="B1" onclick="oMsg()"> </p>
</form>
<p id="wMsg"> Msg1 : <%=request.getAttribute("wMsg")%></p>
<p> Msg2 : <span id="wMsga"> </span> </p>
</body>
</html>
Alguém pode me ajudar? Grato.