Olá pessoal olha eu aqui de novo ,
Estou desenvolvendo um sistema onde tenho uma classe chamada Sobrado que extends a classe Conexao que chama o DB MYSQL , e a view sobrados.jsp. Ai verifiquei o servlet dessa jsp , no netbeans(tem este recurso) diz respeito a linha que chama um get : if (request.getParameter("metodo").equals("incluir")) que está na minha classe Sobrados, estranho disso é que o Tomcat não está pegando esse parametro , e o mais estranho ainda é que as outras classes (Terrenos.java, Casas.java) que estão fazendo a mesma chamada consegue visualizar.... ja olhei aqui e não encontrei nada .... A minha classe é essa:package cadastro;
import java.sql.*;
import java.util.Vector;
/**
*
* @author Adriana
*/
public class Sobrados extends Conexao {
private int codigo;
private String descricao;
private int valor ;
private int oferta ;
// construtor que chama o conexao
public Sobrados(){
conecta () ;
}
public Sobrados (int codigo, String descricao , int valor , int oferta) {
this.codigo = codigo;
this.descricao=descricao ;
this.valor= valor;
this.oferta= oferta;
}
public int getCodigo ()
{
return codigo;
}
public void setCodigo (int codigo)
{
this.codigo = codigo;
}
public String getDescricao ()
{
return descricao;
}
public void setDescricao (String descricao)
{
this.descricao = descricao;
}
public int getValor ()
{
return valor;
}
public void setValor (int valor)
{
this.valor = valor;
}
public int getOferta ()
{
return oferta;
}
public void setOferta (int oferta)
{
this.oferta = oferta;
}
public String getIncluir() {
try {
PreparedStatement sql = conn.prepareStatement(
"insert into sobrados (codigo,descricao,valor, oferta) values (?,?,?,?)");
sql.setInt(1,codigo);
sql.setString(2,descricao);
sql.setInt(3,valor);
sql.setInt (4,oferta);
sql.executeUpdate();
mensagem = "Terreno Incluso!";
}
catch (SQLException ex) {
mensagem = ex.getMessage();
}
return mensagem;
}
public String getAlterar() {
try {
PreparedStatement sql = conn.prepareStatement(
"update sobrados set descricao=?,valor=?,oferta=? where codigo=?");
sql.setString(1, descricao);
sql.setInt(2,valor);
sql.setInt(3, oferta);
sql.setInt(4,codigo);
sql.executeUpdate();
mensagem = "Terreno Alterado";
}
catch (SQLException ex) {
mensagem = ex.getMessage();
}
return mensagem;
}
public String getExcluir() {
try {
PreparedStatement sql = conn.prepareStatement(
"delete from sobrados where codigo=?");
sql.setInt(1, codigo);
int quantExcluidos = sql.executeUpdate(); // atualiza a quantidade de itens exclusos
if (quantExcluidos > 0) {
mensagem = "Terreno Excluido!";
}
else {
mensagem = "Terreno NÃO Excluído";
}
}
catch (SQLException ex) {
mensagem = ex.getMessage();
}
return mensagem;
}
public Vector getListar() {
Vector x = new Vector();
try {
// Joga dados no vetor
PreparedStatement sql = conn.prepareStatement("SELECT *FROM sobrados order by codigo " );
ResultSet rs = sql.executeQuery();
while (rs.next()) {
x.add(new Casas (rs.getInt("codigo"),
rs.getString("descricao"),
rs.getInt("valor"),
rs.getInt("oferta")));
}
rs.close();
}
catch (SQLException ex) {
System.out.println(ex.getMessage());
}
return x;
}
}
a minha pag sobrados.jsp:
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<jsp:useBean id="sobrados" scope="page" class="cadastro.Sobrados"/>
<jsp:setProperty name="sobrados" property="*"/>
<jsp:useBean id="zebra" scope="page" class="cadastro.Zebra"/>
<%@ page language="java" contentType="text/html; charset=iso-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Insert title here</title>
</head>
<body>
<%--INCLUIR--%>
<% if (request.getParameter("metodo").equals("incluir")) { %>
<script>
alert('<jsp:getProperty name="sobrados" property="incluir" />');
</script>
<% }%>
<%--ALTERAR--%>
<%if (request.getParameter("metodo").equals("alterar")) { %>
<script>
alert('<jsp:getProperty name="sobrados" property="alterar" />');
</script>
<% }%>
<%--EXCLUIR--%>
<%if (request.getParameter("metodo").equals("excluir")) { %> // ERRO !
<script>
alert('<jsp:getProperty name="sobrados" property="excluir" />');
</script>
<% }%>
<%@include file="cabecalho.jsp"%>
<%-- inicio formulario --%>
<form action="" method="post" name="form1" id="form1">
<table id="tabelaFormulario" width="400" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr class="tituloform">
<td colspan="2" valign="top">
<table id="tituloForm" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width=60> </td>
<td>
<div align="center" class="tituloform" id="formularioTitulo">SOBRADOS</div>
</td>
<td width=60>
<img align="right" class="dedo" alt="" src=" imagens/fechar.gif" > </td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="60" valign="top" class=titulocampo>
Código:
</td>
<td>
<input name="codigo" type="text" class="campos">
</td>
</tr>
<tr>
<td width="60" valign="top" class=titulocampo> Descrição: </td>
<td><textarea name="descricao" id="descricao"class="campos"></textarea> </td>
</tr>
<tr>
<td width="60" valign="top" class=titulocampo>
Valor:
</td>
<td><input name="valor" type="text" class="campos"> </td>
</tr>
<tr>
<td width="60" valign="top" class=titulocampo>
Oferta:
</td>
<td><input name="oferta" type="text" class="campos"> </td>
</tr>
<tr>
<td width="60" class=titulocampo> </td>
<td>
<input name="Submit" type="submit" class="botao" value="Gravar">
<input name="Cancelar" type="button" class="botao" value="Cancelar">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<%-- inicio linha incluir/busca --%>
<table id="tabelaBusca" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="titulocampo">
<input type="button" value="Incluir"
onClick="form1.action='sobrados.jsp?metodo=incluir';
formularioTitulo.innerHTML='Incluir Novo Imovel';">
|
<input type="button" value="Alterar"
onClick="form1.action='sobrados.jsp?metodo=alterar';
formularioTitulo.innerHTML='Alterar Imovel';">
|
<input type="button" value="Excluir"
onClick="form1.action='sobrados.jsp?metodo=excluir';
formularioTitulo.innerHTML='Excluir Imovel'; ">
</td>
</tr>
</table>
<%-- fim linha incluir/busca --%>
<!--<jsp:getProperty name="sobrados" property="listar" />-->
<%-- inicio listar --%>
<table id="tabelaDados" width="100%" border="0" cellspacing="0" cellpadding="5">
<tr id="linhaTitulos" class="titulocoluna">
<td width="60">
<div class="titulocoluna">
Código
</div>
</td>
<td width="140">
<div class="titulocoluna" >
Descrição:
</div>
</td>
<td width="140">
<div class="titulocoluna" >
Valor:
</div>
</td>
<td width="80">
<div class="titulocoluna" >
Oferta:
</div>
</td>
<td width="80" align="left">
<div class="titulocoluna">Funções</div>
</td>
</tr>
<logic:iterate id="linha" name="sobrados" property="listar">
<tr id="linhaDados" onMouseOver="this.className='selecao';" onMouseOut="this.className='<jsp:getProperty name="zebra" property="corProxima"/>'" align="left" valign="top" class="<jsp:getProperty name="zebra" property="corAtual"/>">
<td class="dados">
<jsp:getProperty name="linha" property="codigo"/>
</td>
<td class="dados">
<jsp:getProperty name="linha" property="descricao"/>
</td>
<td class="dados">
<jsp:getProperty name="linha" property="valor"/>
</td>
<td class="dados">
<jsp:getProperty name="linha" property="oferta"/>
</td>
-
<td class="dados">
<a href="javascript:void(0)" onClick="
alert('Campo atualizado');
">Editar
</a>
|
<a href="excluir.jsp?codigo=<jsp:getProperty name="linha" property="codigo"/>" onClick="
alert('excluir');
">Excluir
</a>
</td>
</tr>
</logic:iterate>
</table>
<%-- fim listar inicio--%>
<%@include file="rodape.jsp"%>
</body>
</html>
Erro no tomcat é esse:
java.lang.NullPointerException
org.apache.jsp.sobrados_jsp._jspService(sobrados_jsp.java:100)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
Valeu galera espero ajuda ......
Adriana