Foros del Web » Programación para mayores de 30 ;) » Java »

ayuda: duda de sintaxis en jsp (novato)

Estas en el tema de ayuda: duda de sintaxis en jsp (novato) en el foro de Java en Foros del Web. tengo la siguiente consulta donde debo poner esta linea: <% if (rs == null) out.println("Usuario no registrado"); %> con esta linea quiero que me muestre ...
  #1 (permalink)  
Antiguo 16/11/2004, 14:14
 
Fecha de Ingreso: noviembre-2004
Mensajes: 67
Antigüedad: 19 años, 5 meses
Puntos: 0
ayuda: duda de sintaxis en jsp (novato)

tengo la siguiente consulta donde debo poner esta linea:

<% if (rs == null) out.println("Usuario no registrado"); %>

con esta linea quiero que me muestre ese mensaje cuando no encuentra en la busqueda el usuario. por que la he puesto en todas partes y no me muestra el mensaje "USUARIO NO REGITRADO". alguien sabe??

..
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection("jdbc:mysql://localhost/base","admin","pass");
st = conn.createStatement();
rs = st.executeQuery("select * from employees where usuario='" + usu + "'");
while(rs.next()) {
%>
<%= rs.getString("nombre") %>
<%
}
%>
<%
}
catch (Exception ex) {
ex.printStackTrace();
%>
<%
}
finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
  #2 (permalink)  
Antiguo 16/11/2004, 16:34
Avatar de goncafa  
Fecha de Ingreso: julio-2002
Ubicación: Santiago
Mensajes: 1.211
Antigüedad: 21 años, 10 meses
Puntos: 10
En realidad estas haciendo la pregunta masl, jamas entrara a ese if...
lo correcto seria esto

Código PHP:
if(!rec.next()) {
    
out.println("Usuario no registrado");
    return;

y debes ponerla justo despues del executeQuery

Saludos
__________________
se despide hasta la proxima
Gonzalo Castillo
  #3 (permalink)  
Antiguo 16/11/2004, 16:50
 
Fecha de Ingreso: noviembre-2004
Mensajes: 67
Antigüedad: 19 años, 5 meses
Puntos: 0
if(!rs.next()) {
out.println("Usuario no registrado");
return;
}

okey lo puse despues del executequery(modificando el !rec por !rs), cuandoingreso alguien qe no esta registrado me muestra el mensaje ·Usuario no registrado", pero cuando ingreso un usuario existente no me despliega los datos.
  #4 (permalink)  
Antiguo 16/11/2004, 16:58
Avatar de goncafa  
Fecha de Ingreso: julio-2002
Ubicación: Santiago
Mensajes: 1.211
Antigüedad: 21 años, 10 meses
Puntos: 10
solo cambia esto...

while(rs.next()) {
%>
<%= rs.getString("nombre") %>
<%
}


por esto

Código:
do {
    rs.getString("nombre");
} while(rs.next());
Saludos
__________________
se despide hasta la proxima
Gonzalo Castillo
  #5 (permalink)  
Antiguo 16/11/2004, 17:28
 
Fecha de Ingreso: noviembre-2004
Mensajes: 67
Antigüedad: 19 años, 5 meses
Puntos: 0
igual me muestra solo los "usuarios no registrados", pero los usuarios registrados no me muestra nada, me podrias ayudar aca esta el codigo mas ordenado:

<html>
<body>
<%@ page import="java.io.*,java.util.*,java.net.*,java.sql. *" %>
<%
String usu = request.getParameter("NOMBRE");
String cla = request.getParameter("CLAVE");
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection("jdbc:mysql://localhost/base","admin","pass");
st = conn.createStatement();
rs = st.executeQuery("select * from employees where usuario='" + usu + "'");
if(!rs.next())
{
out.println("Usuario no registrado");
return;
}
do {
rs.getString("nombre");
rs.getString("apellido");
}
while(rs.next());
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</body>
</html>
  #6 (permalink)  
Antiguo 16/11/2004, 18:19
Avatar de goncafa  
Fecha de Ingreso: julio-2002
Ubicación: Santiago
Mensajes: 1.211
Antigüedad: 21 años, 10 meses
Puntos: 10
Disculpa, no supe explicarme bien denante, pero debes imprimir lo que obientes, falta el out.println

Código PHP:
do {
    
out.ptintln(rs.getString("nombre")); 
    
out.println(rs.getString("apellido"));

Saludos
__________________
se despide hasta la proxima
Gonzalo Castillo
  #7 (permalink)  
Antiguo 16/11/2004, 19:46
 
Fecha de Ingreso: noviembre-2004
Mensajes: 67
Antigüedad: 19 años, 5 meses
Puntos: 0
GRANDE MAESTRO AHORA SI VOY A PODER SEGUIR CON ESTE TUTORIAL
MUCHAS GRACIAS!!!!!!!
  #8 (permalink)  
Antiguo 25/11/2007, 12:28
 
Fecha de Ingreso: noviembre-2007
Mensajes: 1
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: ayuda: duda de sintaxis en jsp (novato)

Oye excelente aporte goncafa, aca lo publico entonces completo para el que necesite hacer validacion de login y password (contraseña) con php:


Cita:
Esta es la pagina login.html:

<html>

<body bgcolor="#FFFFFF" text="#000000">
<div id="wb_Table1" style="position:absolute; left:362px; top:201px; width:281px; height:123px; z-index:1" align="left">
<form name="form1" method="post" action="ordendepedido.jsp">
<table width="106%" border="1" cellpadding="0" cellspacing="1" id="Table1">
<tr>
<td height="36" colspan="2" align="left" valign="top" class="blackshade2"><div align="center">CONECTAR</div></td>
</tr>
<tr>
<td height="45" align="left" valign="top"><p><br>
Documento de usuario:</p>
</td>
<td height="45" ><input name="Docu_clie" type="text" id="Docu_clie"></td>
</tr>
<tr>
<td width="160" height="45" align="left" valign="top"><p align="left"><br>
Contrase&ntilde;a:</p>
</td>
<td width="129" height="45" >
<label>
<input name="cont_clie" type="password" class="main_table_border2" id="cont_clie">
<br>
</label> </td>
</tr>
<tr>
<td height="27" colspan="2" align="left" valign="top"><div align="center"><span>
<input class=button type=submit value="Entrar" name="OK">
</span></div></td>
</tr>
</table> </form>
</div>
</body>
</html>

Este es el ordendepedido.jsp

Cita:
<%@ page import="java.io.*, java.util.*, java.net.*, java.sql.*" %>

<%! int clave=0; %>

<%
Connection conn = null;
Statement stmt_consul=null, stmt_inser = null;
Object dato;
String strcon = "jdbc:mysql://localhost/cotizacion?user=root&password=", q=null;

//conexion a la base de datos
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn=DriverManager.getConnection(strcon);
stmt_inser = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,
ResultSet.CONCUR_UPDATABLE);
} catch(java.lang.ClassNotFoundException e){} catch(SQLException e) {};
ResultSet rs3= null;
String Docu_clie = request.getParameter("Docu_clie");
if(request.getParameter("OK") != null){

String cont_clie = request.getParameter("cont_clie");

try {
rs3 = stmt_inser.executeQuery("select * from cliente where Docu_clie='" + Docu_clie + "' and Cont_clie = '" + cont_clie + "'");
if(!rs3.next())
{
out.println("<h1>Usuario no registrado</h1><META HTTP-EQUIV=REFRESH CONTENT=1;URL=login.jsp>");
return;
}
do {

out.println("<b>Bienvenido "+rs3.getString("Nomb_clie"));
out.println(rs3.getString("apel_clie")+"</b>");
}
while(rs3.next());
}
catch (Exception ex)
{
ex.printStackTrace();
}

}
%>
Saludos!!!

Nelson Contreras
  #9 (permalink)  
Antiguo 18/01/2008, 11:24
 
Fecha de Ingreso: enero-2008
Mensajes: 20
Antigüedad: 16 años, 3 meses
Puntos: 0
Re: ayuda: duda de sintaxis en jsp (novato)

sollimlica:

Copie el código que pusiste pero me parece que hay algo mal, porque cuando pulso el boton de enviar me muestra lo que hay en el jsp de prue,no realiza la validación, te mando el código para ver si puedes ayudarme.

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body bgcolor="#FFFFFF" text="#000000">
<div id="wb_Table1" style="position:absolute; left:362px; top:201px; width:281px; height:123px; z-index:1" align="left">
<form name="form1" method="post" action="prue.jsp">
<table width="106%" border="1" cellpadding="0" cellspacing="1" id="Table1">
<tr>
<td height="36" colspan="2" align="left" valign="top" class="blackshade2"><div align="center">CONECTAR</div></td>
</tr>
<tr>
<td height="45" align="left" valign="top"><p><br>
Documento de usuario:</p>
</td>
<td height="45" ><input name="Docu_clie" type="text" id="Docu_clie"></td>
</tr>
<tr>
<td width="160" height="45" align="left" valign="top"><p align="left"><br>
Contrase&ntilde;a:</p<c:if test=""></c:if>>
</td>
<td width="129" height="45" >
<label>
<input name="cont_clie" type="password" class="main_table_border2" id="cont_clie">
<br>
</label> </td>
</tr>
<tr>
<td height="27" colspan="2" align="left" valign="top"><div align="center"><span>
<input class=button type=submit value="Entrar" name="OK">
</span></div></td>
</tr>
</table> </form>
</div>
</body>
</html>

<%@ page import="java.io.*, java.util.*, java.net.*, java.sql.*" %>

<%! int clave=0; %>

<%
Connection conn = null;
Statement stmt_consul=null, stmt_inser = null;
Object dato;
String strcon = "jdbc:mysql://localhost:3306/pruebas?user=prueba&password=prueba", q=null;

//conexion a la base de datos
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn=DriverManager.getConnection(strcon);
stmt_inser = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,
ResultSet.CONCUR_UPDATABLE);
} catch(java.lang.ClassNotFoundException e){} catch(SQLException e) {};
ResultSet rs3= null;
String Docu_clie = request.getParameter("Docu_clie");
if(request.getParameter("OK") != null){

String cont_clie = request.getParameter("cont_clie");

try {
rs3 = stmt_inser.executeQuery("select * from usuarios where Docu_clie=Bere" + Docu_clie + "' and Cont_clie = 0406" + cont_clie + "'");
if(!rs3.next())
{
out.println("<h1>Usuario no registrado</h1><META HTTP-EQUIV=REFRESH CONTENT=1;URL=vlidacion.jsp>");
return;
}
do {

out.println("<b>Bienvenido "+rs3.getString("Nombre"));
out.println(rs3.getInt("Sueldo")+"</b>");
}
while(rs3.next());
}
catch (Exception ex)
{
ex.printStackTrace();
}

}
%>

Gracias de antemano.

Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:20.