JSP AND BEAN PROBLEmjava.lang.nullpointerexceptionhelp me please
hello i have a problem, when i open login.jsp and enter the form i have nullpointerexception. i don't understand where i wrong... i use tomcat 5.5 ... sorry for my english i'm italian and i speak only italian :(
login.jspthis is the code of the java server page
<html>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="lavoro" scope="page" class="Ok.Dino"/>
<%@ page session="false" %>
<style type="text/css">
<!--
body{
background-color: #003366;
}
a:link{
color: #CCCCCC;
}
.style1{
color: #000000;
font-weight: bold;
font-size: x-large;
}
.style4{font-size: 18px}
-->
</style>
<body>
<%if(request.getMethod()=="GET"){
%>
<form action="login.jsp" method="POST" name="frmlogin" id="frmlogin">
<div align="center">
<p class="style1">AUTENTICAZIONE
<table width="318" height="140" border="1">
<tr>
<td width="95" height="60" bordercolor="#000000" bgcolor="#0066CC"><p align="center"><strong>USER</strong>
</td><td width="207" bgcolor="#0099CC"><p align="center">
<input type="text" name="txtnome">
</td>
</tr>
<tr>
<td height="72" bordercolor="#000000" bgcolor="#0066CC"><strong>PASSWORD</strong> </td>
<td width="207" bgcolor="#0099CC"><div align="center">
<input name="pwdtxt" type="password">
</div></td>
</tr>
</table>
<table width="318" border="1">
<tr>
<td width="318" height="87"> <div align="center">
<input name="submit" type="submit" value="invia" >
</div>
<p align="center"><strong><span class="style4">Se non sei registrato fallo <a href="file:///C|/Documents and Settings/access/Documenti/My Received Files/registrazione.jsp">adesso </a></span></strong>
</td></tr>
</table>
</div>
</form>
<%}else{ %>
<%lavoro.settxtnome(request.getParameter("txtnome"));%>
<%!ResultSet rs=null;
String x=null;
%>
<% lavoro.cn_db("dbutenti");%>
<% rs=lavoro.run_query("SELECT user FROM utenti");%>
<%}%>
</body>
</html>
and this is the bean code
package Ok;
import java.sql.*;
publicclass Dino
{
private String txtnome,pwdtxt;
private Connection cn=null;
private Statement st=null;
private ResultSet Rs=null;
public String gettxtnome()
{
return txtnome;
}
public String getpwdtxt()
{
return pwdtxt;
}
publicvoid settxtnome(String n)
{
this.txtnome=n;
}
publicvoid setpwdtxt(String n)
{
this.pwdtxt=n;
}
publicvoid cn_db(String db)
{
if(cn==null){
//1. Caricamento del driver
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException cnfe){
System.out.println("impossibile caricare il driver");
System.exit(1);
}
try{
//2. Connessione al DB
cn = DriverManager.getConnection("jdbc:odbc:"+db);
//3. creazione degli oggetti Statement e ResultSet
st =cn.createStatement();
}catch(SQLException e){
System.out.println(e+"jjj");
}
}else{
System.out.print("errore database gi脿 creato");
}
}
public ResultSet run_query(String qr)
{
try{
Rs=st.executeQuery(qr);
}catch(SQLException e)
{
System.out.print(e+"ecco l'error");
}
return Rs;
}
}

