Salve ragazzi,
non riesco a far partire questo mio progetto. Ecco il codice:
Index.html:
codice:
<html>
<head>
<title>TopSpeed</title>
<SCRIPT LANGUAGE='JavaScript'>
function verifica_nome()
{
if (document.forms['registrazione']['nome'].value=='')
{
alert("Attenzione: devi inserire il nome!");
document.forms['registrazione']['nome'].focus();
return false;
}
if (document.forms['registrazione']['cognome'].value=='')
{
alert("Attenzione: devi inserire il cognome!");
document.forms['registrazione']['cognome'].focus();
return false;
}
if (document.forms['registrazione']['auto'].value=='')
{
alert("Attenzione: devi inserire il modello dell'auto!");
document.forms['registrazione']['auto'].focus();
return false;
}
return true; //ho fornito il codice => restituisco true e procedo con il submit della form
}
</SCRIPT>
</head>
<body background="auto.jpg">
<h1><p align="center"><font color="blue" size="25" face="arial">Autoconcessionaria TopSpeed</font></p></h1>
<h1><p align="center"><u><font color="red" size="20" face="arial"></font></u></p></h1>
<form NAME="registrazione" method="get" action="inser.jsp" onSubmit="return verifica_nome()">
<fieldset>
<legend><u><font color="blue" size="5" face="arial">Registrazione acquirenti</font></u></legend>
<font color="blue" size="4" face="arial">nome acquirente : </font> <input type="text" name="nome" >
<font color="blue" size="4" face="arial">cognome acquirente : </font> <input type="text" name="cognome" >
<font color="blue" size="4" face="arial">modello auto : </font> <input type="text" name="auto" >
</fieldset>
<input type="submit" value="invia" >
</form>
<form action=http://localhost:8080/autoconcessionaria/jdbc.jsp>
<input type="submit" value="contenuto database">
</form>
</body>
</p>
</html>
inser.jsp:
codice:
<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Scrittura su mySQL Database</title>
</head>
<body>
<h1>Database aggiornato correttamente</h1>
<%
request.getParameter("nome"); //ricezione dalla form i parametri
request.getParameter("cognome");
request.getParameter("auto");
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();
String url="jdbc:mysql://localhost/autoconcessionaria?user=root&password=root";
Connection conn=DriverManager.getConnection(url);
Statement st=conn.createStatement();
st.executeUpdate(" insert into varie(nome,cognome,auto) values(' " +request.getParameter("nome")+ "' , '" +request.getParameter("cognome")+ "' , '" +request.getParameter("auto")+ "')" );
st.close();
conn.close();
%>
<script type="text/javascript"> //reindirizzamento automatico index.html dopo 2 secondi
setTimeout('location.href="http://localhost:8080/autoconcessionaria/index.html"',2000);
</script>
</tbody>
</table>
</center>
</div>
</body>
</html>
jdbc.jsp:
codice:
<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Lettura mySQL Database</title>
</head>
<SCRIPT LANGUAGE='JavaScript'>
function verifica_nome()
{
if (document.forms['cerca']['auto'].value=='')
{
alert("Attenzione: devi inserire l'auto !");
document.forms['cerca']['auto'].focus();
return false;
}
return true; //ho fornito il codice => restituisco true e procedo con il submit della form
}
</SCRIPT>
<body bgcolor="#3399FF">
<h1> <p align="center">Elenco Auto Vendute
<form action="index.html">
<input type="submit" value="ritorna al form" >
</form>
</p> <h1/>
<div align="center" width="85%">
<center>
<table border="1" borderColor="#ffe9bf" cellPadding="0" cellSpacing="0" width="658" height="63">
<tbody>
<td bgColor="blue" width="47" align="center" height="19"><font color="#ffffff">Numero auto vendute</font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Cognome</font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Nome</font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Auto</font></td>
<%
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();
try{
String url="jdbc:mysql://localhost/autoconcessionaria?user=root&password=root";
int i=1;
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from varie ");
while(rst.next())
{
%>
<tr>
<td bgColor="#ffff98" vAlign="top" width="47" align="center" height="19"><%=i%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("cognome")%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("nome")%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("auto")%></td>
</tr>
<%
i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>
<h3>
<form NAME="cerca" method="get" action="jdbc2.jsp" onSubmit="return verifica_nome()">
<p align="center">acquirente da cercare : <input type="text" name="auto" >
<input type="submit" value="invia" >
</form>
</h3>
</body>
</html>
jdbc2.jsp:
codice:
<%@ page language="java" import="java.sql.*"%>
<html>
<head><title>Lettura mySQL Database</title>
</head>
<body bgcolor="#3399FF">
<h1> <p align="center">[i]Elenco Auto Vendute
<form action="index.html">
<input type="submit" value="ritorna al form" >
</form>
[/b]</p> <h1/>
<div align="center" width="85%">
<center>
<table border="1" borderColor="#ffe9bf" cellPadding="0" cellSpacing="0" width="658" height="63">
<tbody>
<td bgColor="blue" width="47" align="center" height="19"><font color="#ffffff"></font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Cognome</font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Nome</font></td>
<td bgColor="blue" width="110" height="19"><font color="#ffffff">Auto</font></td>
<%
request.getParameter("auto");
String DRIVER = "org.gjt.mm.mysql.Driver";
Class.forName(DRIVER).newInstance();
try{
String url="jdbc:mysql://localhost/autoconcessionaria?user=root&password=root";
int i=1;
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery(" select * from varie WHERE auto = '" +request.getParameter("auto")+ "'");
while(rst.next())
{
%>
<tr>
<td bgColor="#ffff98" vAlign="top" width="47" align="center" height="19"><%=i%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("cognome")%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("nome")%></td>
<td bgColor="#ffff98" vAlign="top" width="100" height="19"><%=rst.getString("auto")%></td>
</tr>
<%
i++;
}
rst.close();
stmt.close();
con.close();
}catch(Exception e){
System.out.println(e.getMessage());
}
%>
</tbody>
</table>
</center>
</div>
<form action="jdbc.jsp">
<input type="submit" value="ritorna al database" >
</form>
</body>
</html>
Mi potete dire il motivo?
Grazie!