Fala pessoal estou desenvolvendo um formulario simples com STRUTS 1 e o mesmo ao tentar inserir um registro no banco me da esta exception.
Alguém poderia me dar uma forcinha?
Action
public class ClienteAction extends DispatchAction {
public ActionForward home(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("ok");
}
public ActionForward gravaContato(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
ClienteForm formulario = (ClienteForm) form;
Cliente cliente = formulario.getCliente();
ClienteDao.save(cliente);
return mapping.findForward("ok");
}
ClienteDao
[code]
public class ClienteDao {
public static void save(Cliente cliente) throws Exception{
HibernateUtil.beginTransaction();
HibernateUtil.getSession().save(cliente);
HibernateUtil.commitTransaction();
}
}[/code]
ClienteForm
[code]
public class ClienteForm extends ActionForm {
/**
*
*/
private static final long serialVersionUID = 1L;
private Cliente cliente = new Cliente();
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
}[/code]
model
package vc.sooamorconsegue.model;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
public class Cliente {
@Id
@GeneratedValue
private int id;
private String nome;
private String email;
private Date dataDeNascimento;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getDataDeNascimento() {
return dataDeNascimento;
}
public void setDataDeNascimento(Date dataDeNascimento) {
this.dataDeNascimento = dataDeNascimento;
}
}
struts-config.xml
[code]
<?xml version="1.0" encoding="UTF-8"?><form-beans>
<form-bean name="clienteForm" type="vc.sooamorconsegue.ClienteForm"></form-bean>
</form-beans>
<action-mappings>
<action
path="/cliente"
name="clienteForm"
type="vc.sooamorconsegue.action.ClienteAction"
parameter="method"
scope="request">
<forward name="ok" path="/index.jsp"></forward>
</action>
<action
path="/sooamorconsegue"
type="vc.sooamorconsegue.action.ClienteAction"
scope="request">
<forward name="ok" path="/index.jsp"></forward>
</action>
</action-mappings>
[/code]
Index.jsp
[code]
<table>
<tr>
<td>Nome:</td>
<td>
<input type="text" name="cliente.nome" value="${clienteForm.cliente.nome}">
</td>
<td>Data de Nascimento:</td>
<td>
<input type="text" name="cliente.dataDeNascimento" value="${clienteForm.cliente.dataDeNascimento}">
</td>
<td>E-mail:</td>
<td>
<input type="text" name="cliente.email" value="${clienteForm.cliente.email}">
</td>
<td>
<input type="submit" value="Enviar Dados">
</td>
</tr>
</table>
</form>[/code]
Exception
AVISO: Exception from exceptionCommand 'servlet-exception'
java.lang.NullPointerException
at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:289)
at org.apache.struts.config.FormBeanConfig.createActionForm(FormBeanConfig.java:357)
at org.apache.struts.chain.commands.CreateActionForm.execute(CreateActionForm.java:92)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at vc.sooamorconsegue.filter.HibernateFilter.doFilter(HibernateFilter.java:39)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)