Estou desenvolvendo o meu Projeto de finalização de Curso, criei uma JSP uma SERVELT e uma CLASSE, mais para conseguir mostrar o resultado de um metodo da CLASSE na JP usei o setatribute, o Prof não aceitou. Será que alguem pode me ajudar segue os codigos;
CLASSE
public void getLista(HttpServletRequest request) throws SQLException, ClassNotFoundException{
String sql;
// recupera uma conexao com o banco de dados.
Connection conexao = Util.getConexao();
sql = "select * from \"Funcionarios\" where \"Status\"='1' order by \"Nome\"";
Statement stmt = conexao.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String Lista = "";
while (rs.next()) {
Lista = Lista + "<tr>";
Lista = Lista + "<td align='left' class='tTxt1'><li>"+rs.getString("Nome")+" ("+rs.getString("CPF")+")</li></td>";
Lista = Lista + "<td width='45%' align='right'><table width='100%' border='0' cellspacing='0' cellpadding='0'>";
Lista = Lista + "<tr>";
Lista = Lista + "<td align='center' valign='middle'></span><a ><img /></a></td>";
Lista = Lista + "<td align='center' valign='middle'><span class='tTxt1Negrito'> | </span></td>";
Lista = Lista + "<td align='center' valign='middle'><a ><img /></a></td>";
Lista = Lista + "</tr>";
Lista = Lista + "</table>";
Lista = Lista + "</td>";
Lista = Lista + "</tr>";
}
rs.close();
conexao.close();
//return Lista;
request.setAttribute("ConteudoLista",Lista);
}
SERVLET
[code]package TCC.controle;
import TCC.negocio.Funcionario;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ListaFuncionario extends HttpServlet {
public void listarFuncionario(HttpServletRequest rq) throws ServletException, Exception
{
Funcionario funcionario = new Funcionario();
funcionario.getLista(rq);
}
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
this.listarFuncionario(request);
getServletConfig().getServletContext().getRequestDispatcher("/FuncionarioLista.jsp").forward(request, response);
}catch (Exception e)
{
e.printStackTrace();
System.out.println("ERO"+e.getMessage());
request.setAttribute("erro",e.getMessage());
getServletConfig().getServletContext().getRequestDispatcher("/Erro.jsp").forward(request, response);
}
}
// <editor-fold defaultstate="collapsed" desc="Métodos HttpServlet. Clique no sinal de + à esquerda para editar o código.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
[/code]
JSP
[code]<%@ page contentType=“text/html” pageEncoding=“UTF-8” import=“TCC.negocio.*” %>
<%@ include file=“VerifLoginAdminFunc.jsp” %>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
<title> SGH | Funcionarios > Lista …</title>
<link href=“Css.css” rel=“stylesheet” type=“text/css”>
</head>
<body>
<table width=“100%” height=“600” border=“0” align=“center” cellpadding=“0” cellspacing=“0”>
<tr>
<td valign=“top”><table width=“100%” height=“600” border=“0” cellspacing=“0” cellpadding=“0”>
<tr>
<td height=“70” colspan=“3”><%@ include file=“Topo.jsp” %></td>
</tr>
<tr>
<td width=“200” valign=“top”><%@ include file=“Menu.jsp” %></td>
<td colspan=“2” valign=“top” bgcolor="#FFFFFF" width=“100%”>
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="5">
<tr>
<td height="30" align="left">
<table width="98%" height="30" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="24" valign="middle" background="Imagens/BG_subtitulo.gif" class="tTxt3Negrito">Funcionarios > Lista</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="top"><table width="100%" border="0" cellspacing="5" cellpadding="1">
<!-- Lista Conteúdo - Pacientes -->
${ConteudoLista}
</table></td>
</tr>
<tr>
<td height="20" align="center"> </td>
</tr>
<tr>
<td align="center"><a >voltar</a></td>
</tr>
<tr>
<td align="center"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="25" colspan="3"><%@ include file="Rodape.jsp" %></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
[/code]
GOSTARIA QUE FOSSE JSP–>SERVLET–>CLASSE–>SERVLET–>JSP.
OBRIGADO