Pessoal,
Estou tentando passar parametros pelo <jsp:setProperty… />
Aqui estão os códigos
index.jsp (um html simples)
<html>
<body>
<form action="index2.jsp" method="post">
Nome: <input TYPE=text NAME=nome><br>
Endereço: <input type="text" name=end><br>
Telefone: <input type="text" name="tel"><br>
Sobrenome: <input type="text" name="lastnome"><br>
<input type="submit"><br>
</form>
</body>
</html>
index2.jsp (beans)
<jsp:useBean id="theBean" scope="page" class="teste.beans.TesteSQL">
<jsp:setProperty name="theBean" property="*" />
<%
theBean.setSql();
%>
</jsp:useBean>
teste.beans.TesteSQL
/*
* Created on 22/11/2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package teste.beans;
/**
* @author João Victor
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.sql.*;
public class TesteSQL {
private String nome = "";
private String end;
private String lastname;
private String tel;
private String sql;
public void banco()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:teste");
Statement sta = con.createStatement();
sta.executeUpdate(sql);
}
catch (Exception ex)
{
System.out.println("erro");
}
}
public void setSql()
{
sql = "INSERT INTO TESTE (nome, end, tel, lastname) values ('";
sql = sql + nome + "', '" + end + "', '" + tel + "', '" + lastname + "')";
System.out.println(sql);
}
}
E ele “printa” os valores todos como null, a não ser a String nome, que ele printa como “” (string vazia).
Obrigado
