Ecco quanto ho fatto invece nella mia pagina jsp di log-in:
codice:
<body>
<%
String nomutente = request.getParameter("r");
String pass = request.getParameter("s");
Connection connection = null;
try {
Class.forName(DRIVER).newInstance();
} catch (ClassNotFoundException e) {
System.out.println("Where is your MySQL JDBC Driver?");
}
System.out.println("MySQL JDBC Driver Registered!");
try {
connection = DriverManager.getConnection(db, "root", "");
} catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
String query = "SELECT * from utenti where user=? and password=? ";
try {
PreparedStatement pstm = connection.prepareStatement(query);
pstm.setString(1, nomutente);
pstm.setString(2, pass);
ResultSet rs = pstm.executeQuery();
while (!rs.next()) {
if (nomutente.compareTo(rs.getString(1))==0) {
if (rs.getString(3) == "a") {%>
<h1 style="color: green">Benvenuto <%rs.getString(1); %> </h1>
<%} else {%>
<h1 style="color: red "> Benvenuto <%rs.getString(1); %> </h1>
<%}
} else {
out.println("<h1><strong>LogIn errato--->RITORNO PAGINA LOGIN");
%>
<a href="index.jsp">Pagina log-in</a>
<%
}
}
}
catch (SQLException ex){
out.println("<h1>Errore</h1>");
}
%>
</body>
</html>
Ci tengo a precisare che sono un neofita della programmazione web, non trattatemi troppo male