Carcleo 4 Denunciar post Postado Junho 29, 2015 Observação: todos os outros retornos funciona normal. Se quiser pegar o zip que fiz esta no endereço: http://funerariasaopedro.net.br/imwsaogotardo.zip Compartilhar este post Link para o post Compartilhar em outros sites
Vergil 15 Denunciar post Postado Junho 29, 2015 Você precisa aprender a usar JSTL. Não dá pra se fazer coisas do tipo: <c:if test="listaDeProfessores.getListaProfessores().isEmpty()"> O correto seria <c:if test="${empty listaDeProfessores.listaProfessores}"> http://docs.oracle.com/cd/E17904_01/web.1111/e13712/reference.htm#WBAPP429 Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 vergy, desculpe, foi mau! mas como disse, essa manobra funcionou perfeitamente bem! O problema esta na parte que disse. Mas vou alterar aqui pois quero aprender direito! Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 concertei lá! Ma o que esta pegando é que, embora a consulta esteja sendo feito corretamente, o retorno da String esta sempre chegando null package dao.sala; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import util.Conexao; public class ListaSala { Connection conexao = null; public ListaSala() { conexao = Conexao.getConnection(); } public String getNomeSala(int _id) { String sala = null; try { PreparedStatement pesquisaSala = conexao.prepareStatement("select nome from sala where id = ?"); pesquisaSala.setInt(1, _id); ResultSet ls = pesquisaSala.executeQuery(); sala = ls.getString("nome"); } catch (SQLException e) { e.printStackTrace(); } System.out.println(sala+"tttttttt"); return sala; } } Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 Observei que quando coloco o System.out.println() Antes do ResultSet, ele funciona. Depois do ResultSet não funciona! public String getNomeSala(int _id) { String sala = null; try { PreparedStatement pesquisaSala = conexao.prepareStatement("select nome from sala where id = ?"); pesquisaSala.setInt(1, _id); ResultSet ls = pesquisaSala.executeQuery(); System.out.println("Teste1"); // Funciona sala = ls.getString("nome"); System.out.println("Teste2"); // Não Funciona } catch (SQLException e) { e.printStackTrace(); } System.out.println(sala+"tttttttt"); return sala; } O que pode ser se a consulta funciona normal no workbenq (MySQL)? Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 Resolvida essa parte. ResultSet pede while() Outra coisa: ${nomeSala.getNomeSala(${professores.sala})} Porque não funciona? ${nomeSala.getNomeSala()} Depende do valor de ${professores.sala} Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 Resolvi setando uma variavel. por favor, veja se fiz coisa fora de padrão <div id="indexMeio"> <jsp:useBean id="listaDeProfessores" class="dao.professor.ListaProfessores" /> <jsp:useBean id="nomeSala" class="dao.sala.ListaSala" /> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <table style="border-collapse: collapse;border: 1px solid; text-align:center"> <tr style="background-color:#000; color:#FFF"> <th style="padding:3px;width:200px;height:50px;text-align:center;">NOME</th> <th style="padding:3px;width:100px;height:50px;text-align:center;">LOGIN</th> <th style="padding:3px;width:100px;height:50px;text-align:center;">INCLUSÃO</th> <th style="padding:3px;width:200px;height:50px;text-align:center;">SALA</th> <th style="padding:3px;width:100px;height:50px;text-align:center;">EDITAR</th> <th style="padding:3px;width:100px;height:50px;text-align:center;">TROCAR SENHA</th> <th style="padding:3px;width:100px;height:50px;text-align:center;">BLOQ/DESBLOQ</th> <th style="padding:3px;width:100px;height:50px;align:center;">EXCLUIR</th> </tr> <c:set var="lista" value="${empty listaDeProfessores.getListaProfessores()}" /> <c:choose> <c:when test="${lista == true}"> <tr> <td colspan=8 style="padding:3px;width:200px;height:30px;text-align:center;">Não há registros!</td> </tr> </c:when> <c:otherwise> <c:forEach items="${listaDeProfessores.getListaProfessores()}" var="professores"> <c:if test="${professores.status=='b'}"> <c:set var="status" value="d" /> <c:set var="imgEdicao" value="desbloquear.png" /> </c:if> <c:if test="${professores.status=='d'}"> <c:set var="status" value="b" /> <c:set var="imgEdicao" value="bloquear.png" /> </c:if> <c:set var="nomeDaSala" value="${professores.sala}" /> <tr> <td style="padding:3px;width:200px;height:30px;text-align:left;">${professores.nome}</td> <td style="padding:3px;width:100px;height:30px;text-align:left;">${professores.login}</td> <td style="padding:3px;width:100px;height:30px;text-align:center;">${professores.dataCadastro}</td> <td style="padding:3px;width:200px;height:30px;text-align:left;">${nomeSala.getNomeSala(nomeDaSala)}</td> <td style="padding:3px;width:100px;height:30px;text-align:center;"><a href="editar.jsp?acao=form&id=${professores.id}"><img src="_img/editar.png" style='height: 30px'/></a></td> <td style="padding:3px;width:100px;height:30px;text-align:center;"><a href="senha.jsp?acao=form&id=${professores.id}"><img src="_img/senha.png" style='height: 30px'/></a></td> <td style="padding:3px;width:100px;height:30px;text-align:center;"><a href="ProfessorServlet?acao=BloqueiaProfessor&status=${status}&id=${professores.id}"><img src="_img/${imgEdicao}" style='height: 30px' /></a></td> <td style="padding:3px;width:100px;height:30px;text-align:center;"><a href="ProfessorServlet?acao=ExcluiProfessor&id=${professores.id}"><img src="_img/excluir.png" style='height: 30px'/></a></td> </tr> </c:forEach> </c:otherwise> </c:choose> </table> </div>' Compartilhar este post Link para o post Compartilhar em outros sites
Carcleo 4 Denunciar post Postado Junho 29, 2015 Bom. acho que consegui (essa parte) atualizei os arquivos lá para caso vocês quiserem ver. Agora preciso de fazer uma combobox, select option, para selecionar as salas no cadastro do professor. Mas isso, vai trazer uma sql no jsp. Alguma orientação quanto a Padrão de Projeto quanto a isso? Compartilhar este post Link para o post Compartilhar em outros sites