Ciao a tutti,
questa servlet, divenuta sempre di più oggetto dei miei studi...
cosi funziona...:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class Login extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
String USR = request.getParameter("usr");
String PWD = request.getParameter("pws");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection=DriverManager.getConnection("jdbcdbc:login");
Statement statement = connection.createStatement();
String sql="SELECT * FROM Nominativi where username = '"+USR+"' and password='"+PWD+"'";
ResultSet rs = statement.executeQuery(sql);
boolean abilitato= false;
while(rs.next()){
abilitato = true;
}
response.setContentType("text/html");
PrintWriter out = new PrintWriter (response.getOutputStream());
out.println("<html>");
out.println("<head><title>Autenticazione</title></head>");
out.println("<body bgColor=#33CCFF");
if (abilitato)
{
out.println("<HR>
<h1> **** Sei autenticato...!!! **** </h1>");
}else{
out.println("
<h1> **** NON autenticato...!!! **** </h1>");
}
out.println("</body></html>");
connection.close();
out.close();
}
catch (SQLException e)
{
}
catch(ClassNotFoundException e)
{
}
catch(Throwable theException)
{
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
doGet(request, response);
} // end doPost(...)
}
solo che ho deciso.. (spinto da un atto di follia.... ) di stampare anche i record triovati... e così mi son lanciato andando un pò per intuito..... e vedendo un pò le librerie
ho messo nel ciclo questo:
String Nome = rs.getString("Nome");
String Cognome = rs.getString("Cognome");
out.printl("NOME:::: "+Nome);
ma come già immaginate contuiìinua a darmi errore...
Ma come si fa a stampare semplicemente dei record trovati con una servlet..?
Ciao Giuseppe