Pessoal, tô fazendo um sisteminha do zero pra aprender mais struts, bem do zero mesmo, somente com struts 1.3.5, sem hibernate/spring, pois sempre trabalhei com sistemas “já montados”. mas qdo clico no botão enviar do CadastroClienteCadastro.jsp não funciona, a pag fica na mesma… a seguir coloco os meus códigos. alguém sabe oq fazer?
public class CadastroClienteAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.getInputForward();
}
public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
CadastroClienteForm meuForm = (CadastroClienteForm) form;
CadastroClienteModel.insert(meuForm.getNome(), meuForm.getEndereco(), meuForm.getTelefone(),
meuForm.getEmail());
return mapping.findForward("cadastroClienteConsulta");
}
}
public class CadastroClienteForm extends ActionForm{
private String nome;
private String endereco;
private String telefone;
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (StringUtils.isNumeric(nome)) {
errors.add("org.apache.struts.action.GLOBAL_MESSAGE",
new ActionMessage("error.nome.invalid"));
}
return errors;
}
}
public class CadastroClienteModel {
static final String JDBC_DRIVER = "org.postgresql.Driver";
static final String DATABASE_URL = "jdbc:postgresql://localhost:5432/agenda";
static final String LOGIN_ROOT = "postgres";
static final String SENHA_ROOT = "netel";
public static Connection getConnection() {
Connection connection = null; // gerencia a conexão
try {
Class.forName( JDBC_DRIVER ); // carrega classe de driver do banco de dados
connection = DriverManager.getConnection( DATABASE_URL, LOGIN_ROOT, SENHA_ROOT );// estabelece conexão
System.out.println("Sucesso ao conectar ao banco");
} // fim do try
catch (SQLException sqlException) {
sqlException.printStackTrace();
System.exit( 1 );
} // fim do catch
catch (ClassNotFoundException classNotFound){
classNotFound.printStackTrace();
System.exit( 1 );
} // fim do catch
return connection;
}//fim de getConnection()
public static void insert(String nome, String endereco, String telefone, String email) {
try {
Statement statement = getConnection().createStatement();
ResultSet resultSet = statement.executeQuery("INSERT INTO CONTATOS (nome, endereco, telefone, email) " +
"VALUES ("+ nome +","+ endereco +","+ telefone +","+ email + ")");
}
catch (SQLException e) {
e.printStackTrace();
}
}//fim de insert(String nome, String endereco, String telefone, String email)
}
meu struts-config.xml ta mapeado assim com form-bean e action:
<form-bean name="CadastroClienteForm"
type="teste.form.CadastroClienteForm" />
<action path="/cadastroCliente"
type="teste.action.CadastroClienteAction"
name="CadastroClienteForm"
scope="request"
validate="true"
input="/WEB-INF/pages/CadastroClienteCadastro.jsp"
parameter="method">
<forward name="cadastroClienteConsulta" path="/WEB-INF/pages/CadastroClienteConsulta.jsp"></forward>
</action>
e meu CadastroClienteCadastro.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ include file="/WEB-INF/pages/aqua/taglib.jsp" %>
<%@ include file="/WEB-INF/pages/aqua/menu.jsp" %>
<html:form action="cadastroCliente">
<bean:message key="cadastroCliente.nome.label"/>
<html:text property="nome" size="50" maxlength="30"></html:text>
<br><br>
<bean:message key="cadastroCliente.endereco.label"/>
<html:text property="endereco" size="50" maxlength="30"></html:text>
<br><br>
<bean:message key="cadastroCliente.telefone.label"/>
<html:text property="telefone" size="50" maxlength="30"></html:text>
<br><br>
<bean:message key="cadastroCliente.email.label"/>
<html:text property="email" size="50" maxlength="30"></html:text>
<br><br>
<center><input type="submit">
</center>
</html:form>