Código:
public void busquedaYMuestra(HttpServletRequest request,HttpServletResponse response,Connection conn) throws IOException{ PrintWriter out = response.getWriter(); PreparedStatement pst; ResultSet rs; String consulta; String ape = request.getParameter("modApellido"); String doc = request.getParameter("modDocumento"); String usu = request.getParameter("modUsuario"); String mai = request.getParameter("modDirmail"); String leg = request.getParameter("modLegajo"); consulta = "SELECT Apellido,Nombre,TipoDoc,NumDoc,FechaNac FROM persona " + "INNER JOIN alumnos WHERE IdPersona = PERSONA_IdPersona AND "; if(!ape.isEmpty()){ consulta+="Apellido = \""+ape+"\" AND "; } if(!doc.isEmpty()){ consulta+="NumDoc = \""+doc+"\" AND "; } if(!usu.isEmpty()){ consulta+="Usuario = \""+usu+"\" AND "; } if(!mai.isEmpty()){ consulta+="Mail = \""+mai+"\" AND "; } if(!leg.isEmpty()){ consulta+="Legajo = \""+leg+"\" AND "; } consulta=consulta.substring(0, consulta.length()-5); request.getSession(); try{ pst=conn.prepareStatement(consulta); rs=pst.executeQuery(); if(rs.next()){ //verifica que el resultset tenga algo rs.beforeFirst(); out.print("<h2>Resultados:</h2>"); out.print("<table border=1 id='tablares'>"); while(rs.next()){ out.println("<tr>"); out.print("<td>"+rs.getString(1)+"</td><td>"+rs.getString(2) +"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4) +"</td><td>"+rs.getString(5)); out.println("</tr>"); } } else{ out.print("<h4>No hay usuarios con esas caracteristicas</h4>"); } } catch(SQLException e){ System.out.println("SQLException en busquedaYMuestra"); } }