paginação web

Boa galera boa tarde a todos,
Assunto paginação:
Temos poucos recursos, certo?
Tentei utilizar as taglib ( display e Page ) sem sucesso ( caso algum amigo tenha um exemplo que possa me passar agradeço valmir@shelter.inf.br ).
Recentemente consegui um código bem legal e fácil, nem tudo na vida são rosas… tem uma parte no código que ainda não resolvi e solicito aos amigos ajuda.

Estou recebendo a clausula and por request.getParameter , qual o erro?
Quando clicko no link para o próximo grupo de dados, a pagina fica em branco come se não tivesse dados … Melhor não passa a String . Teria solução para isso?
Pensei em que, ao invés de receber a passar direto para query, fazer o seguinte armazenar e daí passar para query… mais infelizmente não sei como fazer, os amigos poderiam me ajudar?

[code]

<%@page contentType=“text/html”%>
<%@page pageEncoding=“UTF-8”%>
<%@ page language=“java” %>
<%@ page import=“java.sql.*”%>
<%@ page import=“java.sql.Date”%>
<%–
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library… action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
–%>
<%–
<%@taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
–%>

      <%  
   String setor2 = (String) request.getParameter("grupo");
   
  %> 
      
  <%
//Connection con = null;

Statement st  = null;
ResultSet rs   = null;  
ResultSet rst  = null;             
            
            
            try {
                String setor = (String) request.getParameter("grupo");
	            String setor3 = (String) request.getParameter("grupo");

//String dsn = “jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/Atn/DB/RJJ0802.mdb”;
//String usuario = “”;
//String senha = “”;
//String sql = “”;
//Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”).newInstance();
//Connection con = DriverManager.getConnection(dsn,usuario,senha);

    String url="jdbc:mysql://localhost:3306/shelter"; 
	Class.forName("org.gjt.mm.mysql.Driver");
	Connection con = DriverManager.getConnection(url, "root", "1272");

  %>
  <%

st = con.createStatement();
rst = st.executeQuery
//(“Select * from Ramal”);

	  //("Select  Sum(IIf(CRJJ02.tipo = 0, 1, 0)) As efetuadas, Sum(IIf(CRJJ02.tipo = 1, 1, 0)) As recebidas From Ramal, CRJJ02 " +
       //"where Ramal.ramal = CRJJ02.origem And grupo = '"+ setor3 +"' And data = date() ");
       
	   ("select count(recebida) as recebidas, count(n_discado) as efetuadas From tb_ligacoes L, ramal R " + 
	   "where R.ramal = L.ramal And R.grupo = '"+ setor3 +"' ");
	   
	   
        while (rst.next()){
        
    %>
    <%

st = con.createStatement();
rs = st.executeQuery
// (“Select ramal, Sum(IIf(CRJJ02.tipo = 0, 1, 0)) As efetuadas, Sum(IIf(CRJJ02.tipo = 1, 1, 0)) As recebidas From Ramal, CRJJ02 " +
// “where Ramal.ramal = CRJJ02.origem And grupo = '”+ setor +”’ And data = date() Group by Ramal.ramal");

	  ("select  R.ramal, count(recebida) as recebidas, count(n_discado) as efetuadas From tb_ligacoes L, ramal R " + 
	   "where R.ramal = L.ramal And R.grupo = '"+ setor +"' Group by R.ramal ");                  
      %>
    <table width="100%">
      <tr>
        <td width="2%" height="125">&nbsp;</td>
        <td width="90%"><fieldset>
          <legend>Sumário por ramal referente ao setor:<span class="style3"> <%=setor2%></span></legend>
         
 
Ligações Efetuadas
Ligações Recebidas
Ligações não atendidas
 
 
<%= rst.getString("efetuadas") %>
<%= rst.getString("recebidas") %>
   
Ramal
Ligações Efetuadas
Ligações Recebidas
<% while (rs.next()){ String grupo = rs.getString("ramal");
       %>
<% out.print ( ""+grupo+""); %>
<%= rs.getString("efetuadas") %>
<%= rs.getString("recebidas") %>
<% } %>

 

 
<p>&nbsp;</p>
<p>&nbsp; </p>
          
</table>                     
        
        <% 
        
        }               
        } catch (Exception ex) {
        ex.printStackTrace();
        } finally {
        if (rst != null) rst.close();
        if (rs != null) rs.close();
        if (st != null) st.close();
       // if (con != null) con.close();
        }
        %>
[/code]

ou caso alguem tenha um codigo exemplo, passe por favor para o e-mail acima.

Grato

o galera foi mal passei o codigo errado, segue o certo:

[code]<%@ page language=“java” import=“java.sql.*” %>

<%

String setor = (String) request.getParameter(“grupo”);
//String setor3 = (String) request.getParameter(“grupo”);

String url = “jdbc:mysql://localhost/shelter”;
String usuario = “root”;
String senha = “1272”;

Connection conn = null;

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, usuario, senha);

}
catch(SQLException ex){
out.println("SQLException: " + ex.getMessage() + “
”);
out.println("SQLState: " + ex.getSQLState() + “
”);
out.println("VendorError: " + ex.getErrorCode() + “
”);
}
catch(Exception e){
out.println(“Problemas ao tentar conectar com o banco de dados”);
}

// conn é a conexão com o banco de dados
int limit = 15; // quantidade de resultados por página

// obtém a quantidade de registros
PreparedStatement pstmt = conn.prepareStatement
(“select count(*) as c From ramal R where R.grupo = '”+ setor +"’ ");

//(“select count() as c From tb_ligacoes L, ramal R where R.ramal = L.ramal And R.grupo = ativos ");
// ("SELECT COUNT(
) AS c FROM TB_LIGACOES where ramal = 1037”);
ResultSet rs = pstmt.executeQuery();
rs.next();
int total_rows = Integer.parseInt(rs.getString(“c”));

String pagina = request.getParameter(“pagina”); // página atual
if(pagina == null){
pagina = “1”;
}

int limitValue = (Integer.parseInt(pagina) * limit) - limit;

PreparedStatement pstmt2 = conn.prepareStatement
(“select R.ramal, count(recebida) as recebidas, count(n_discado) as efetuadas From tb_ligacoes L, ramal R " +
“where R.ramal = L.ramal And R.grupo = '”+ setor +”’ Group by R.ramal LIMIT " + limitValue + ", " + limit );

// ("SELECT * FROM TB_LIGACOES where ramal = 1037 LIMIT " + limitValue + ", " + limit);
ResultSet rs2 = pstmt2.executeQuery();

%>

<%
while(rs2.next()) {

  out.print("<tr>\n<td>" + rs2.getString("RAMAL") + "</td>");
  out.print("<td>" + rs2.getString("efetuadas") + "</td>");
  out.print("<td>" + rs2.getString("recebidas") + "</td>");
  out.print("</tr></td>\n</tr>");
  

//int id = rs2.getInt("RAMAL");
//out.println("ID: " + id + "<br>");
//String nome = rs2.getString("N_DISCADO");
//out.println("NOME: " + nome + "<br>");
//int idade = rs2.getInt("OPERADORA");
//out.println("IDADE: " + idade + "<br><br>");

}

%>

Ramal Ligações efetuadas Ligações recebidas

<%
int anterior;
if(Integer.parseInt(pagina) != 1){
anterior = Integer.parseInt(pagina) - 1;
out.println("<a href=?pagina=" + anterior + “>” + limit + " Anteriores");
}
else
out.println(limit + " Anteriores ");

int numOfPages = total_rows / limit;
int i;

for(i = 1; i <= numOfPages; i++){
if(i == Integer.parseInt(pagina)){
out.println("" + i + " “);
}
else{
out.println(”<a href=?pagina=" + i + “>” + i + " ");
}
}

if((total_rows % limit) != 0){
if(i == Integer.parseInt(pagina)){
out.println(i + " “);
}
else{
out.println(”<a href=?pagina=" + i + “>” + i + " ");
}
}

int proxima;
if((total_rows - (limit * Integer.parseInt(pagina))) > 0){
proxima = Integer.parseInt(pagina) + 1;

out.println("<a href=?pagina=" + proxima + ">Próximos " + limit + "</a>");  

}
else
out.println("Próximos " + limit);
%>

[/code]

estou em busca da solução do mesmo problema se alguém souber gostaria tb…

de saber como é …

Vamos manter contato… quem arrumar ajuda o outro
msn valmir.net@hotmail.com

Você já tentou usar a displaytag, é simples e seu código fica bem mais limpo:
http://displaytag.homeip.net/displaytag-examples-1.1/example-paging.jsp

A idéia é jogar uma lista no request e pronto a taglib se vira montando para você.

[quote=Pedrosa]Você já tentou usar a displaytag, é simples e seu código fica bem mais limpo:
http://displaytag.homeip.net/displaytag-examples-1.1/example-paging.jsp

A idéia é jogar uma lista no request e pronto a taglib se vira montando para você.[/quote]
Isso ai, essa é a melhor solucao.
E ainda voce consegue otimizar a paginacao pegando os parametros (numero da pagina corrente, coluna para ordenar,etc) da display tag para montar o sql.

Flw

Ta mais oq não consigo e montar o ambiente .
Voce poderia me passar um ex. de tag.

tipo vou usar um bd mysql … e uso o netbeans 5.5…

agradeço pelo ajuda.
Valmir lopes.

o galera vamos ajudar aí

http://forum.mentaframework.org/posts/list/193.page#3276

Tags simples e vc tem uma paginação completa de qualquer lista no estilo Google.

E vc ainda pode customizar a vontade no seu html.

exemplo mto fácil e bom de paginação sem usar displaytag…

http://www.laliluna.de/struts-paging-tutorial.html

opa, tem um exemplo também usando displaytag no msmo link