Erro em página JSP/Servlet
Pessoal, é o seguinte... tou com um erro que todo mundo já teve alguma vez na vida e cada um deu jeito de uma forma diferente. Tentei todas as alternativas que encontrei pela net e nada resolveu meu problema.
O erro é o:
"HTTP Status 404 - /Indicadores/relatorios/ServletPrincipal
type Status report
message /Indicadores/relatorios/Se /Indicadores/relatorios/ServletPrincipal
orios/ServletPrincipal
description The requested resource (/Indicadores/relatorios/ServletPrincipal) is not available.
Apache Tomcat/5.5.17"
Na realidade meu servlet não está na pasta relatorios e sim na Indicadores/src/java/Controle, sei que o erro é algum mapeamento, mas não consigo resolver.
Estou usando:
Netbeans 5.5.1
JDK 6
Windows XP
Mantive a estrutura de diretórios que o próprio netbeans utiliza.
Abaixo, trechos mais relevantes do código:
ServletPrincipal.java
CODE
package Controle;
import Modelo.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.JOptionPane;
/**
*
* @author renata
* @version beta
*/
public class ServletPrincipal extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession sessao = req.getSession();
if (req.getParameter("action").equals("INS")){
Indicador i = new Indicador();
i.setCodIndicador(Integer.parseInt(req.getParameter("codigo")));
i.setDescIndicador(req.getParameter("descricao"));
//System.out.println("Mensagem:" + req.getParameter("nome"));
i.setCodSegmento(Integer.parseInt(req.getParameter("codSegmento")));
i.setCodCategoria(Integer.parseInt(req.getParameter("codCategoria")));
i.setMeta(Double.parseDouble(req.getParameter("meta")));
IndicadorDAO id = new IndicadorDAO();
try {
id.inserir(i);
req.setAttribute("sucesso","s");
req.getRequestDispatcher("cadastro_autor.jsp").forward(req,resp);
} catch (SQLException ex) {
ex.printStackTrace();
req.setAttribute("erro",ex.getMessage());/*incluiumainformação adicional à requisição.Inclui o nome do atributo e que valor ele vai ter*/
/*Exemplo: cria um novo atributo chamado erro e este vai receber o conteudo de c.getmessage*/
/*como fica: req.setAttribute( "erro ",c.getmessage()) e req.getRequestDispatcher("error.jsp ").forward(req,res);;*/
req.getRequestDispatcher("Error.jsp").forward(req,resp);/*Essa instrução empacota uma requisição e despacha pra quem ele quiser*/
}
}
if (req.getParameter("action").equals("SEL")){
IndicadorDAO id = new IndicadorDAO();
try {
ArrayList al = new ArrayList();
al = id.selecionaLista(req.getParameter("descIndicador"));
req.setAttribute("lista", al);
if(al.isEmpty()){
req.setAttribute("sucesso","s");
}
JOptionPane.showMessageDialog(null, "Ok");
//req.getRequestDispatcher("index.jsp").forward(req,resp);
} catch (SQLException ex) {
req.setAttribute("erro",ex.getMessage());
req.getRequestDispatcher("error.jsp").forward(req,resp);
}
}
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
Web.xml
CODE
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="[http://java.sun.com/xml/ns/j2ee"](http://java.sun.com/xml/ns/j2ee) xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance) xsi:schemaLocation="[http://java.sun.com/xml/ns/j2ee](http://java.sun.com/xml/ns/j2ee) [http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">](http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>)
<servlet>
<servlet-name>ServletConsulta</servlet-name>
<servlet-class>Controle.ServletConsulta</servlet-class>
</servlet>
<servlet>
<servlet-name>ServletPrincipal</servlet-name>
<servlet-class>Controle.ServletPrincipal</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletConsulta</servlet-name>
<url-pattern>/ServletConsulta</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ServletPrincipal</servlet-name>
<url-pattern>/ServletPrincipal</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
rel_unid_nao_lanc.jsp
CODE
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link href="../Estilo.css" rel="stylesheet" type="text/css">
</head>
<body>
<table class="pagina">
<form id="lancar" name="lancar" method="post" action="ServletPrincipal">
<tr>
<td><fieldset>
<legend style="color:#000000">Unidades sem Lançamento</legend>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="20px"><input type="hidden" name="action" id="action" value="SEL"></td>
<td height="50">Indicador:</td>
<td height="50"><input type="text" name="descIndicador" id="descIndicador" size="30" value="Objetos Entregues" />
<!--Este size indica a largura em caracteres--></td>
<td height="50"><img src="../Imagens/search.gif" alt="buscar" width="16" height="16" /></td>
</tr>
</table></td>
</tr>
<tr>
<td height="70"><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="30"> </td>
<td width="130" height="30">Meses Disponíveis </td>
<td height="30"> </td>
<td height="30">Meses a Pesquisar </td>
<td height="30"> </td>
</tr>
<tr>
<td width="80"> </td>
<td width="130"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15"> </td>
<td width="115"><select name="meses_disponiveis" size="12" multiple style="border:#000066; width:100">
<option>Jan/2008</option>
<option>Dez/2007</option>
<option>Nov/2007</option>
<option>Out/2007</option>
</select></td>
</tr>
</table></td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="25" height="25"><img src="../Imagens/play_16x16.gif" width="16" height="16"></td>
</tr>
<tr>
<td width="25" height="25"><img src="../Imagens/fast_forward_16x16.gif" width="16" height="16"></td>
</tr>
<tr>
<td width="25" height="25"><img src="../Imagens/play_reverse_16x16.gif" width="16" height="16"></td>
</tr>
<tr>
<td width="25" height="25"><img src="../Imagens/reverse_16x16.gif" width="16" height="16"></td>
</tr>
</table></td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15"> </td>
<td width="115"><select name="meses_pesquisar" size="12" multiple id="meses_pesquisar" style="border:#000066; width:100" title="Meses">
<option>Jan/2008</option>
<option>Dez/2007</option>
<option>Nov/2007</option>
<option>Out/2007</option>
</select></td>
</tr>
</table></td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="50" align="center"><table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="130"> </td>
<td>Relatório: </td>
<td><input type="checkbox" name="checkbox" value="checkbox" tabindex="9">
.xls </td>
<td><input type="checkbox" name="checkbox2" value="checkbox" tabindex="10">
.pdf</td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td align="center"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr >
<td width="33%" height="25"> </td>
<td width="60" height="25" align="center"><img src="../Imagens/relatorio_16x16.gif" alt="Salvar" width="16" height="16" /></td>
<td width="30" height="25" align="center"> <img src="../Imagens/search.gif" alt="Cancelar" width="16" height="16" /></td>
<td width="35%" height="25"><label>
<input type="submit" name="Submit" value="OK">
</label></td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr >
<td width="30%" height="15"> </td>
<td width="60" height="15" align="center"> Gerar </td>
<td width="30" height="15" align="center"> Visualizar </td>
<td width="30%" height="15"> </td>
</tr>
</table></td>
</tr>
</table>
</fieldset></td>
</tr>
</form>
</table>
</body>
</html>Discussão (31)
Carregando comentários...