TEnho a classe TRABCOMPOST abaixo.
package meupacotePOST;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TrabComPost extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void destroy(){//ESSE METODO LIBERA RECURSOS QUE ESTAVAM SENDO USADOS PELO SERVLET
super.destroy(); //E É CHAMADO QUANDO É FINALIZADO PELO SERVIDOR EM QUE ESTÁ SENDO EXECUTADO
}
protected void doPost(HttpServletRequest request, HttpServletResponse response){
try {
String usuario = request.getParameter("usuario");
String senha = request.getParameter("senha");
String html = "<html>"
+"<head>"
+"<title>Trabalhando com POST em Servlet</title>"
+"</head>"
+"<body>";
if(usuario.equals("Alerson") && senha.equals("123")){
html += "Seja bem vindo Alerson";
} else {
html += "Usuário ou senha inválidos";
}
html += "</body></html>";
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.print(html);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void init(){
try {
super.init();
} catch (ServletException e) {
e.printStackTrace();
e.getMessage();
}
}
}
Tenho o formulario.html abaixo.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Formulario</title>
</head>
<body>
<form action="PrimeiraPagina" method="post">
Login:<input type="text" name="usuario" /><br />
Senha:<input type="password" name="senha" /><br />
<input type="submit" value="Logar" />
</form>
</body>
</html>
E tenho o .xml mapeando o caminho a fazer, que no caso eu quero que entre no METODO POST e imprima a mensagem " seja bem vindo Alerson " ou “usuário ou senha invalidos” mas não estou conseguindo, algume poderia me ajudar. A QUESTÃO É: QUANDO EU ENTRO COM O USUARIO E A SENHA, AO INVEZ DELE ME MOSTRAR A MENSAGEM NA TELA… ELE MOSTRA NO HTTP// DO BROWSER… OU SEJA LÁ ONDE DIGITAMOS O LINK…
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>AplicacaoUsandoPOST</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TrabComPost</servlet-name>
<servlet-class>meupacotePOST.TrabComPost</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TrabComPost</servlet-name>
<url-pattern>/PrimeiraPagina</url-pattern>
</servlet-mapping>
</web-app>
Desde ja agradeço.