amigos, eu fiz uma página para efetuar login em um sistema, estou utilizando um arquivo index.jsp onde contém o formulário inicial:
<%--
Document : index
Created on : 18/08/2008, 19:23:01
Author : Alessandro
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Acesso ao Sistema</title>
</head>
<body>
<h2>Digite sua identificação para acessar o sistema:</h2>
<form name="login" action="login.jsp" method="POST">
<table width="250" border="0">
<tr>
<td width="14%">Usuário: </td>
<td width="86%"><input type="text" name="usuario" value="" /></td>
</tr>
<tr>
<td>Senha: </td>
<td><input type="password" name="senha" value="" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Validar" /></td>
</tr>
</table>
<p> </p>
<p> </p>
<p><br/>
<br/>
</p>
</form>
</body>
</html>
que chama por consequencia o arquivo login.jsp:
<%--
Document : login
Created on : 19/08/2008, 16:02:16
Author : Alessandro
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.*" %>
<%@page import="java.sql.*" %>
<%@page import="alessandro.Conexoes"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sistema!</title>
</head>
<body>
<%
String usuario = request.getParameter("usuario");
String senha = request.getParameter("senha");
try {
Conexoes conexao = new Conexoes();
ResultSet resultado = conexao.executeQuery("SELECT login FROM usuarios WHERE login = '" +usuario+ "' and senha = '"+senha+"'");
if ( !resultado.next()) {
%> Usuario ou senha errados <%
} else {%>
Conectado
<% session.setAttribute("usuario", usuario);
}
} catch (Exception e) {
throw new Exception(e.getMessage());
}
%>
</body>
</html>
este arquivo utiliza o arquivo Conexoes.java para efetuar a conexão com o banco e consultas:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package alessandro;
//import java.sql.SQLException;
//import com.mysql.jdbc.Connection;
import java.sql.*;
//import java.io.*;
//import java.util.*;
/**
*
* @author Alessandro
*/
public class Conexoes {
private Connection connection;
public Conexoes() throws Exception {
String driver = ("com.mysql.jdbc.Driver");
String url = ("jdbc:mysql://localhost/empresa");
String user = ("root");
String password = ("neuza");
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, password);
} catch (ClassNotFoundException e) {
String msg = "Driver JDBC não encontrado : " + driver;
throw new Exception (msg);
} catch (SQLException e) {
String msg = "Erro na conexão ao banco de dados : \n" +
"url = " + url + "\n" +
"usuário = " + user + "\n" +
"senha = " + password;
throw new Exception (msg);
} catch (Exception e) {
String msg = "Erro não esperado : " + e.getMessage();
throw new Exception (msg);
}
}
public final ResultSet executeQuery (String sql ) throws Exception {
Statement statement = connection.createStatement();
return statement.executeQuery(sql);
}
public final int executeUpdate (String sql ) throws Exception {
Statement statement = connection.createStatement();
return statement.executeUpdate(sql);
}
@Override
public void finalize () throws Exception {
connection.close();
}
}
desta forma que colei acima funciona rodando no netbeans. aí o que eu fiz foi colocar pra rodar separadamente, com o tomcat 6 aí eu troquei uma linha do login.jsp
retirei:
<%@page import="alessandro.Conexoes"%>
coloquei:
<jsp:useBean id="Conexoes" scope="page" class="Conexoes" />
mas ao rodar a aplicação no tomcat ele apresenta o erro:
org.apache.jasper.JasperException: /login.jsp(11,0) The value for the useBean class attribute Conexoes is invalid.
pelo que entendi ele nao encontra o Conexoes.java, deve estar em local errado, nao sei. se alguem puder me ajudar agradeço desde já.
Obs: os arquivos index.jsp e login.jsp estao em C:\Arquivos de programas\Apache Software Foundation\Tomcat 6.0\webapps\loja e o Conexoes.java está em C:\Arquivos de programas\Apache Software Foundation\Tomcat 6.0\webapps\loja\WEB-INF\alessandro
abraços