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} |