Olá pessoal!
Então eu fiz 2 paginas jsp(pagina1.jsp e pagina2.jsp) a pagina1.jsp chama um servlet que recebe os valores do formulario por post e chama a pagina2.jsp.
A página2.jsp recebe os valores tudo certo.
Porém se eu digito no browser http://localhost:8080/GravarContatos/pagina2.jsp?nome=Alexandre&cpf=111.111.111-11 a pagina2.jsp recebe os valores por GET e POST, mas eu gostaria que recebesse apenas por POST.
alguém poderia me ajudar?
Abaixo os arquivos:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>GravarContatos</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>AdicionaPessoa</servlet-name>
<servlet-class>gravar.PessoaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdicionaPessoa</servlet-name>
<url-pattern>/adicionaPessoa</url-pattern>
</servlet-mapping>
</web-app>
pagina1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Pagina1.jsp<br /><br />
<form id="form1" name="form1" action="adicionaPessoa" method="post">
Nome:<input id="nome" name="nome" type="text">
CPF:<input id="cpf" name="cpf" type="text">
<input type="submit" value="Enviar" >
</form>
</body>
</html>
pagina2.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Pagina2.jsp<br /><br />
Nome = ${param.nome} <br />
CPF = ${param.cpf}
</body>
</html>
PessoaServlet.java
package gravar;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PessoaServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
// recuperando os parametros da pagina1
String param1 = request.getParameter("nome");
String param2 = request.getParameter("cpf");
// setando os parametros para a pagina2
request.setAttribute("nome", param1);
request.setAttribute("cpf", param2);
// despachando a request para pagina2
RequestDispatcher dispatcher = request.getRequestDispatcher("/pagina2.jsp");
dispatcher.forward(request, response);
}
}
Obrigado.