Lintando usando Action....apostila caelum

6 respostas
L

galera quando eu tento listar usando action não da...aparece o erro 404...

mais eu jah revisei meu código todo...e num consegui ver onde ta o erro

quando eu adiciono...ele adiciona numa boa, sem erros

obrigado por quem ajudar...

segue os códigos...

[size=18]classe Action[/size]

package br.com.cfr.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import br.com.cfr.jdbc.dao.TarefaDAO;
import br.com.cfr.jdbc.modelo.Tarefa;


public class ListaTarefasAction {
	
	private List<Tarefa> tarefas;
	
	
	@Action(value="listaTarefas", results= {
	@Result(name="ok", location="lista-tarefas.jsp")
	})
	public String execute() {
	tarefas = new TarefaDAO().lista();
	return "ok";
	}
	public List<Tarefa> getTarefas() {
	return tarefas;
	}
	
}

[size=18]o código dp DAO [/size]

package br.com.cfr.jdbc.dao;

  
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import br.com.cfr.jdbc.ConnectionFactory;
import br.com.cfr.jdbc.modelo.Tarefa;
 
public class TarefaDAO { 
     
    Connection connection; 
     
    public TarefaDAO(){ 
        this.connection = new ConnectionFactory().getConnection(); 
    } 
     
    public void adiciona (Tarefa tarefa){ 
         
        String sql = "insert into tab_tar (descricao , finalizado) value(?,?)"; 
         
        try { 
            PreparedStatement stmt = connection.prepareStatement(sql); 
            stmt.setString(1, tarefa.getDescricao()); 
            stmt.setString(2, tarefa.getFinalizado());
             
            stmt.execute(); 
            stmt.close();                
        } catch (SQLException e){ 
            throw new RuntimeException (e); 
        } 
         
         
         
    }
 
     
 
      public List<Tarefa> lista() {
            try {
                  List<Tarefa> tarefas  = new ArrayList<Tarefa>();
                  PreparedStatement stmt = this.connection.prepareStatement("select * from tab_tar");
                  ResultSet rs = stmt.executeQuery();
                 
                  while (rs.next()){
                       
                        Tarefa tarefa = new Tarefa();
                        tarefa.setId(rs.getLong("id"));
                        tarefa.setDescricao(rs.getString("descricao"));
                        tarefa.setFinalizado(rs.getString("finalizado"));
                       
                        tarefas.add(tarefa);
                  }
                  rs.close();
                  stmt.close();
                  return tarefas;  
                 
            } catch (SQLException e) {
                  throw new RuntimeException(e);
            }    
      }
 
      public void remove(Tarefa tarefa) {
           
            try {
                  PreparedStatement stmt = connection.prepareStatement("delete from tab_tar where id=?");
                  stmt.setLong(1, tarefa.getId());
                  stmt.execute();
                  stmt.close();
            } catch (SQLException e) {
                  throw new RuntimeException(e);
            }
    }
           
      }

e o jsp

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>


Criar nova tarefa


















Id Descrição Finalizado
${tarefa.id} ${tarefa.descricao} ${tarefa.finalizado}


6 Respostas

Cleidson

Verifica se há um possivel bloqueio do seu conteiner(localhost)
e se estiver usando o windows 7, ele tem essas manias de permissão ocultas
onde você instala um aplicativo e ele joga suas politicas de segurança sobre ele!
para fazer um teste, crie um ponto de restauração antes, depois desista-le o seu localhost e instale ele na unidade D: ou até mesmo na pasta " meus documentos" ou “documentos”, e faça um teste e verifica se para de dar esse erro!

L

o meu eh o win vista…

Cleidson

pergunta, seu conteiner estar rolando fulll?
sem nenhuma limitação ou bloqueio?
verifique que acho que isso deve resolver

L

como assim container??

eu fiz td conforme a apostila da caelum…

e tava rodando td na web…só o lista q num roda…

L

up

L

up

Criado 20 de outubro de 2011
Ultima resposta 20 de out. de 2011
Respostas 6
Participantes 2