Onde sera q esta o erro

1 resposta
TASF

boa tarde tenho a seguinte servlet de conexao

package br.com.projecao.login;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.projecao.bean.Usuario;
import br.com.projecao.conexao.Conexao;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String acao = null;
		if(request.getParameter("acao") != null){
			acao = request.getParameter("acao");
		}
		
		if(acao.equals("efetuarLogin")){
			efetuarLogin(request, response);
		}else if(acao.equals("cadastrar")){
			cadastrar(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String acao = null;
		if(request.getParameter("acao") != null){
			acao = request.getParameter("acao");
		}
		
		if(acao.equals("efetuarLogin")){
			efetuarLogin(request, response);
		}else if(acao.equals("cadastrar")){
			cadastrar(request, response);
		}
	}
	
	
	private void efetuarLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String login = "Teste";
		String senha = "123456";
		
		String loginJSP = null;
		if(request.getParameter("login") != null){
			loginJSP = request.getParameter("login");
		}
		
		String senhaJSP = null;
		if(request.getParameter("senha") != null){
			senhaJSP = request.getParameter("senha");
		}
		
		if(loginJSP != null && loginJSP.equals(login) && 
				senhaJSP != null && senhaJSP.equals(senha)){
			request.setAttribute("usuario", login);
			gotoPage("/paginas/cadastro.jsp", request, response);
		}else{
			String msg = "Usuario/Senha estão errados!";
			request.setAttribute("msg", msg);
			gotoPage("/index.jsp", request, response);
		}
	}
	
	private void cadastrar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String nome = null;
		if(request.getParameter("nome") != null){
			nome = request.getParameter("nome");
		}
		
		String cpf = null;
		if(request.getParameter("cpf") != null){
			cpf = request.getParameter("cpf");
		}
		
		String tel = null;
		if(request.getParameter("tel") != null){
			tel = request.getParameter("tel");
		}
		
		String is_ativo = null;
		if(request.getParameter("is_ativo") != null){
			is_ativo = request.getParameter("is_ativo");
		}
		
		String est_civil = null;
		if(request.getParameter("est_civil") != null){
			est_civil = request.getParameter("est_civil");
		}
		
		String rg = null;
		if(request.getParameter("rg") != null){
			rg = request.getParameter("rg");
		}
		String dt_cadastro = null;
		if(request.getParameter("dt_cadastro") != null){
			dt_cadastro = request.getParameter("dt_cadastro");
		}
		
		
		String msg = "";
		if(nome != null && cpf != null && tel !=null && is_ativo != null && dt_cadastro !=null){
			Usuario u = new Usuario(nome,cpf,tel,rg,est_civil,is_ativo,dt_cadastro);
			try {
				msg = new Conexao().cadastrarUsuario(u);
				request.setAttribute("Usuario", u);
			} catch (SQLException e) {
				e.printStackTrace();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		request.setAttribute("msg", msg);
		gotoPage("/paginas/cadastroSucesso.jsp", request, response);
	}	
	
	public void gotoPage(String page, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
		if(page != null){
			dispatcher.forward(request, response);
		}		
	}

}

e a pagina de cadastro da 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">
<%
	String usuario = null;
	if(request.getAttribute("usuario") != null){
		usuario = (String)request.getAttribute("usuario");
	}
%>
<html>
<head>

<script type="text/javascript">
function ValidarDados (){
	i=document.getElementById ('is_ativo').selectedIndex;
var nome;
var estado;
var dt_cad;
var cpf;
var tel;
var rg;
var teste = true;
var saida = "O(s) Seguinte(s) Campo(s) é (são) obrigatório(s):";
if (document.getElementById ('nome').value == ''){
	saida += "\nNome";
	teste = false;
	}else{
		nome =document.frmCadastro.nome.value+"\n";
		 tel =document.frmCadastro.tel.value+"\n";
		 cpf = document.frmCadastro.cpf.value+"\n";
		 estado = document.frmCadastro.is_civil.value+"\n";
		 rg= document.frmCadastro.rg.value+"\n";
		 dt_cad= document.frmCadastro.dt_cad.value+"\n";
				
	}
	if (document.getElementById ('cpf').value == ''){
		saida += "\ncpf";
		teste = false;
		}
	if(document.getElementById ('is_ativo').options[i].value==""){
		saida += "\nEstado [Ativo/inativo]";
		teste = false;

		}

		if (document.getElementById ('tel').value == ''){
		saida += "\ntelefone";
		teste = false;
		}

		if (document.getElementById ('dt_cadastro').value == ''){
			saida += "\ndata do cadastro";
			teste = false;
			}
	
if (teste){
alert ();
return true;
}else{
alert (saida);
return false;
}
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>:::... Cadastro ...:::</title>
</head>
<body>
<%if(usuario != null){ %>
<p style="color: red; font: bold;"><%=usuario %></p>
<%} %>	
	<form action="/Login/LoginServlet?acao=cadastrar" method="post" id="frmCadastro" name="frmCadastro">
		<table>
			<tr>
				<td>
					Nome:
				</td>
				<td>
					<input type="text" name="nome" id="nome" maxlength="80" size="50">
				</td>
			</tr>
			<tr>
				<td>
					cpf:
				</td>
				<td>
					<input type="text" name="cpf" id="cpf" maxlength="80" size="50">
				</td>
			</tr>
			
			<tr>
				<td>
					telefone:
				</td>
				<td>
					<input type="text" name="tel" id="tel" maxlength="80" size="50">
				</td>
				
				<tr>
				<td>
					RG:
				</td>
				<td>
					<input type="text" name="rg" id="rg" maxlength="80" size="50">
				</td>
			</tr>
			
			<tr>
				<td>
					Estado Civil:
				</td>
				<td>
					<input type="text" name="est_civil" id="est_civil" maxlength="80" size="50">
				</td>
			</tr>
			<tr >
				<td>Estado:</td>
					<td >
						<select id="es_ativo" name="es_ativo">
							<option>_____SELECIONE______</option>
							<option value="Ativo">Ativo</option>
							<option value="Inativo">Inativo</option>
						</select>
					</td>
				</tr>
				
			
			
			</tr>
			
			<tr>
				<td>
					<input type="submit" value="Salvar" onclick="return ValidarDados ();">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

porem na hona de que envio os dados me aparece a msg de ERRO 500 disendo null poin exception onde

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	br.com.projecao.login.LoginServlet.gotoPage(LoginServlet.java:142)
	br.com.projecao.login.LoginServlet.cadastrar(LoginServlet.java:136)
	br.com.projecao.login.LoginServlet.doPost(LoginServlet.java:57)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NullPointerException
	org.apache.jsp.paginas.cadastroSucesso_jsp._jspService(cadastroSucesso_jsp.java:89)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	br.com.projecao.login.LoginServlet.gotoPage(LoginServlet.java:142)
	br.com.projecao.login.LoginServlet.cadastrar(LoginServlet.java:136)
	br.com.projecao.login.LoginServlet.doPost(LoginServlet.java:57)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.26

pq disso??
grato pela foça de vcs galera !!

1 Resposta

Hebert_Coelho

O que tem nessa linha? org.apache.jsp.paginas.cadastroSucesso_jsp._jspService(cadastroSucesso_jsp.java:89)

Criado 30 de novembro de 2011
Ultima resposta 30 de nov. de 2011
Respostas 1
Participantes 2