Estou com o seguinte problema tenho uma página JSP que passa parâmetros por método Post para uma Servlet, essa Servlet processa esses parâmetros e por final deve repassar através da URL (método Get) alguns parametrôs para outra Servlet. Porém estou tendo o erro abaixo. Este erro acontece porque minha Servlet esta tentando passar parâmetros pela URL através do método Post. Agora chegamos ao ponto eu não sei como fazer uma servlet receber requisições por Post e devolver respotas por Get.
HTTP Status 405 - HTTP method POST is not supported by this URL
type Status report
message HTTP method POST is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method POST is not supported by this URL).
PÁGINAS JSP E SERVLET CITADAS
[code]<%@page contentType=“text/html” pageEncoding=“ISO-8859-1”%>
JSP Page <% String id = request.getParameter("idNoticia"); String tabela = request.getParameter("tabela"); %> <form name="formulario" method="POST" action="ImagemCadastra" enctype="multipart/form-data" >
IdNoticia:<input type="text" name="idNoticia" value="<%out.print(id);%>" /><br>
Tabela:<input type="text" name="tabela" value="<%out.print(tabela);%>" /><br>
Imagem: <input type="file" name="imagem" value=""/>
<p><input type="submit" value="Enviar" name="Enviar" /></p>
</form>
[/code]
[code]public class ImagemCadastra extends HttpServlet
{
private Integer idNoticia;
private String tabela;
private String nome;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
Imgagem imagem = new Imagem();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart)
{
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try
{
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (item.getFieldName().equals("idNoticia"))
{
idNoticia = Integer.parseInt(item.getString());
}
if (item.getFieldName().equals("tabela"))
{
tabela = item.getString();
}
if(!item.isFormField())
{
if (item.getName().length() > 0)
{
nome = tabela+"_"+id;
imagem.inserirImagemDiretorio(nome, item, 640, 640, nome+".jpeg");
}
}
}
}
catch (FileUploadException fuex)
{
fuex.getMessage().toString();
}
catch (Exception ex)
{
ex.getMessage().toString();
}
//AQUI É ONDE OCORRE O ERRO
//NÃO SEI QUE COMANDO UTILIZAR PARA DEVOLVER PARÂMETROS PELA URL
RequestDispatcher view = request.getRequestDispatcher("/AnexoNoticia?idNoticia="+idNoticia+"&tabela="+tabela);
view.forward(request, response);
//FIM DE ONDE OCORRE O ERRO
}
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
processRequest(request, response);
}
}[/code]