Haber mi código es el siguiente :
Código HTML:
Ver original<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
if (request.getParameter("entrar") != null) {
//out.println("Si");
int count = 0;
try {
String connectionURL = "jdbc:oracle:thin:@localhost:1521:asixjg";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
connection = DriverManager.getConnection(connectionURL, "misql", "misql");
statement = connection.createStatement();
String QueryString = "SELECT * from p_usuarios WHERE id=" + request.getParameter("usuario") + " AND password='" + request.getParameter("pass") + "'";
rs = statement.executeQuery(QueryString);
while (rs.next()) {
count++;
}
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
System.out.println("Que no puede conectar::: " + ex);
}
//out.println(count);
if (count == 1) {
String username = request.getParameter("usuario");
if (username == null) {
username = "";
}
Cookie cookie = new Cookie("id", username);
cookie.setMaxAge(60 * 60);
response.addCookie(cookie);
%>
<script type="text/javascript"> document.location.href='clients.jsp';
<%
} else {
%>
<script type="text/javascript"> document.location.href='error.jsp';
<% }
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> body {
font-family:Arial, Verdana, Helvetica;
}
#caja_login {
position:absolute;
top:50%;
left:50%;
margin-top:-50px;
margin-left:-130px;
height:100px;
width:260px;
}
<form action="" method="post"><!-- es crida a si mateix--> <%
try{
String connectionURL = "jdbc:oracle:thin:@localhost:1521:asixjg";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
connection = DriverManager.getConnection(connectionURL, "misql", "misql");
statement = connection.createStatement();
String QueryString;
QueryString = "SELECT ID from p_clientes ";
rs = statement.executeQuery(QueryString);
%>
<%
while (rs.next()) {
%>
<option value="<%out.println(rs.getString("id")); %>" id="usuario" name="usuario" >
<%out.println(rs.getString("id")); %></option> <% }%>
<input type="text" name="usuario" id="usuario"></td> <td><input type="password" name="pass" id="pass"></td> <td><input type="submit" name="entrar" id="entrar" value="Entrar"></td> <%
rs.close();
statement.close();
connection.close();}
catch (Exception ex) {
System.out.println("Que no puede conectar::: "+ex);
}
%>
Tengo un campo ID usuario que introduzco el usuario a mano.
Y otro campo que me dice los ID que hay en la BD, es para que te enseñe los que hay.
funciona correctamente el campo input .
Lo que me falla es el select option creo que no enviada nada, por que ?????
Alguna ayuda ?