daveiga 12 de jun. de 2012
Em que linha exatamente é o nullpointer?
Esse erro ocorre quando você tenta acessar um membro (Método, atributo) de um objeto que não foi inicializado com um “new”.
Nesse caso qualquer um dos parâmetros que chegou à sua action pode ser vindo nulo, devido à uma falha na configuração fora do escopo da sua action, e quando você tentou usá-lo esse erro foi disparado.
azubokoff 12 de jun. de 2012
e ai jamesfrj blz,
provavelmente o erro é referente ao teu ContatoDAO(). primeiro vc cria um Objeto do tipo ContatoDAO depois vc chama o procura().
jamesfrj 13 de jun. de 2012
daveiga, o NullPointer ocorre nesta linha:
Blz, alezubokoff!
Justamente, conforme o código abaixo eu faço isso que você falou
MostraContatoForm formulario = (MostraContatoForm) form;
Contato contato = formulario.getContato();
Contato encontrado = new ContatoDAO().procura(contato.getId());
request.setAttribute("contato", encontrado);
Só não sei se estou fazendo da maneira certa, rs
drsmachado 13 de jun. de 2012
Como está o struts-config.xml?
jamesfrj 13 de jun. de 2012
Fala drsmachado! Segue o struts-config.xml
<struts-config>
<form-beans>
<form-bean name= "ContatoForm" type= "br.com.caelum.struts.form.ContatoForm" ></form-bean>
<form-bean name= "RemoveContatoForm" type= "br.com.caelum.struts.form.RemoveContatoForm" ></form-bean>
<form-bean name= "MostraContatoForm" type= "br.com.caelum.struts.form.MostraContatoForm" ></form-bean>
</form-beans>
<action-mappings>
<action path= "/alteraContato" type= "br.com.caelum.struts.action.AlteraContatoAction" >
<forward name= "ok" path= "/listaContatos.do" />
</action>
<action path= "/mostraContato" type= "br.com.caelum.struts.action.MostraContatoAction" >
<forward name= "ok" path= "/mostraContato.do" />
</action>
<action path= "/mudaIdioma" type= "br.com.caelum.struts.action.MudaIdiomaAction" >
<forward name= "ok" path= "/testa-mensagens.jsp" />
</action>
<action path= "/removeContato" name= "RemoveContatoForm"
type= "br.com.caelum.struts.action.RemoveContatoAction" >
<forward name= "ok" path= "/listaContatos.do" ></forward>
</action>
<action path= "/novoContato" name= "ContatoForm" input= "/novo.jsp"
type= "br.com.caelum.struts.action.AdicionaContatoAction" scope= "request" >
<forward name= "ok" path= "/listaContatos.do" ></forward>
</action>
<action path= "/teste" type= "br.com.caelum.struts.action.TesteSimplesAction" >
<forward name= "ok" path= "/exemplo.jsp" ></forward>
</action>
<action path= "/listaContatos" type= "br.com.caelum.struts.action.ListaContatosAction" >
<forward name= "lista" path= "/lista.jsp" />
<forward name= "vazia" path= "/lista-vazia.jsp" ></forward>
</action>
</action-mappings>
<!-- <message-resources parameter="MessageResources" />-->
</struts-config>
drsmachado 13 de jun. de 2012
Não está faltando definir o atributo name desta action?
<action path= "/mostraContato" type= "br.com.caelum.struts.action.MostraContatoAction" >
<forward name= "ok" path= "/mostraContato.do" />
</action>
jamesfrj 13 de jun. de 2012
Você estava certo, drsmachado! Adicionei o atributo name na action o meu struts-config.xml
<form-beans>
<form-bean name= "ContatoForm" type= "br.com.caelum.struts.form.ContatoForm" ></form-bean>
<form-bean name= "RemoveContatoForm" type= "br.com.caelum.struts.form.RemoveContatoForm" ></form-bean>
<form-bean name= "MostraContatoForm" type= "br.com.caelum.struts.form.MostraContatoForm" ></form-bean>
</form-beans>
<action-mappings>
<action path= "/alteraContato" name= "AlteraContatoForm" type= "br.com.caelum.struts.action.AlteraContatoAction" >
<forward name= "ok" path= "/listaContatos.do" />
</action>
<action path= "/mostraContato" name= "MostraContatoForm" type= "br.com.caelum.struts.action.MostraContatoAction" >
<forward name= "ok" path= "/mostraContato.jsp" />
</action>
e agora passei por aquele problema! Porém agora está ocorrendo um outro erro nesta linha do MostraContatoAction
O erro que ocorre é este:
GRAVE : Servlet . service () for servlet jsp threw exception
javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . struts . taglib . html . FormTag . lookup ( FormTag . java : 881 )
at org . apache . struts . taglib . html . FormTag . doStartTag ( FormTag . java : 488 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fform_005f0 ( mostraContato_jsp . java : 156 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fhtml_005f0 ( mostraContato_jsp . java : 106 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 72 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 70 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 388 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 313 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 260 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . ApplicationDispatcher . invoke ( ApplicationDispatcher . java : 646 )
at org . apache . catalina . core . ApplicationDispatcher . processRequest ( ApplicationDispatcher . java : 436 )
at org . apache . catalina . core . ApplicationDispatcher . doForward ( ApplicationDispatcher . java : 374 )
at org . apache . catalina . core . ApplicationDispatcher . forward ( ApplicationDispatcher . java : 302 )
at org . apache . struts . chain . commands . servlet . PerformForward . handleAsForward ( PerformForward . java : 113 )
at org . apache . struts . chain . commands . servlet . PerformForward . perform ( PerformForward . java : 96 )
at org . apache . struts . chain . commands . AbstractPerformForward . execute ( AbstractPerformForward . java : 54 )
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 . doGet ( ActionServlet . java : 449 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 617 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 293 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $Http11ConnectionHandler . process ( Http11Protocol . java : 602 )
at org . apache . tomcat . util . net . JIoEndpoint $Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
13 /06/ 2012 10 : 05 : 10 org . apache . struts . chain . commands . AbstractExceptionHandler execute
AVISO : Unhandled exception
org . apache . jasper . JasperException : javax . servlet . ServletException : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . jasper . servlet . JspServletWrapper . handleJspException ( JspServletWrapper . java : 502 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 412 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 313 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 260 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . ApplicationDispatcher . invoke ( ApplicationDispatcher . java : 646 )
at org . apache . catalina . core . ApplicationDispatcher . processRequest ( ApplicationDispatcher . java : 436 )
at org . apache . catalina . core . ApplicationDispatcher . doForward ( ApplicationDispatcher . java : 374 )
at org . apache . catalina . core . ApplicationDispatcher . forward ( ApplicationDispatcher . java : 302 )
at org . apache . struts . chain . commands . servlet . PerformForward . handleAsForward ( PerformForward . java : 113 )
at org . apache . struts . chain . commands . servlet . PerformForward . perform ( PerformForward . java : 96 )
at org . apache . struts . chain . commands . AbstractPerformForward . execute ( AbstractPerformForward . java : 54 )
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 . doGet ( ActionServlet . java : 449 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 617 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 293 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $Http11ConnectionHandler . process ( Http11Protocol . java : 602 )
at org . apache . tomcat . util . net . JIoEndpoint $Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : javax . servlet . ServletException : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . jasper . runtime . PageContextImpl . doHandlePageException ( PageContextImpl . java : 865 )
at org . apache . jasper . runtime . PageContextImpl . handlePageException ( PageContextImpl . java : 794 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 79 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 70 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 388 )
... 33 more
Caused by : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . struts . taglib . html . FormTag . lookup ( FormTag . java : 881 )
at org . apache . struts . taglib . html . FormTag . doStartTag ( FormTag . java : 488 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fform_005f0 ( mostraContato_jsp . java : 156 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fhtml_005f0 ( mostraContato_jsp . java : 106 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 72 )
... 36 more
13 /06/ 2012 10 : 05 : 10 org . apache . struts . chain . commands . ExceptionCatcher postprocess
AVISO : Exception from exceptionCommand 'servlet-exception'
org . apache . jasper . JasperException : javax . servlet . ServletException : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . jasper . servlet . JspServletWrapper . handleJspException ( JspServletWrapper . java : 502 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 412 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 313 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 260 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . ApplicationDispatcher . invoke ( ApplicationDispatcher . java : 646 )
at org . apache . catalina . core . ApplicationDispatcher . processRequest ( ApplicationDispatcher . java : 436 )
at org . apache . catalina . core . ApplicationDispatcher . doForward ( ApplicationDispatcher . java : 374 )
at org . apache . catalina . core . ApplicationDispatcher . forward ( ApplicationDispatcher . java : 302 )
at org . apache . struts . chain . commands . servlet . PerformForward . handleAsForward ( PerformForward . java : 113 )
at org . apache . struts . chain . commands . servlet . PerformForward . perform ( PerformForward . java : 96 )
at org . apache . struts . chain . commands . AbstractPerformForward . execute ( AbstractPerformForward . java : 54 )
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 . doGet ( ActionServlet . java : 449 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 617 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 293 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $Http11ConnectionHandler . process ( Http11Protocol . java : 602 )
at org . apache . tomcat . util . net . JIoEndpoint $Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
Caused by : javax . servlet . ServletException : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . jasper . runtime . PageContextImpl . doHandlePageException ( PageContextImpl . java : 865 )
at org . apache . jasper . runtime . PageContextImpl . handlePageException ( PageContextImpl . java : 794 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 79 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 70 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 388 )
... 33 more
Caused by : javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . struts . taglib . html . FormTag . lookup ( FormTag . java : 881 )
at org . apache . struts . taglib . html . FormTag . doStartTag ( FormTag . java : 488 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fform_005f0 ( mostraContato_jsp . java : 156 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fhtml_005f0 ( mostraContato_jsp . java : 106 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 72 )
... 36 more
13 /06/ 2012 10 : 05 : 10 org . apache . catalina . core . StandardWrapperValve invoke
GRAVE : Servlet . service () for servlet testeDeStruts threw exception
javax . servlet . jsp . JspException : Cannot retrieve definition for form bean : "AlteraContatoForm" on action : "/alteraContato.do"
at org . apache . struts . taglib . html . FormTag . lookup ( FormTag . java : 881 )
at org . apache . struts . taglib . html . FormTag . doStartTag ( FormTag . java : 488 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fform_005f0 ( mostraContato_jsp . java : 156 )
at org . apache . jsp . mostraContato_jsp . _jspx_meth_html_005fhtml_005f0 ( mostraContato_jsp . java : 106 )
at org . apache . jsp . mostraContato_jsp . _jspService ( mostraContato_jsp . java : 72 )
at org . apache . jasper . runtime . HttpJspBase . service ( HttpJspBase . java : 70 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . jasper . servlet . JspServletWrapper . service ( JspServletWrapper . java : 388 )
at org . apache . jasper . servlet . JspServlet . serviceJspFile ( JspServlet . java : 313 )
at org . apache . jasper . servlet . JspServlet . service ( JspServlet . java : 260 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . ApplicationDispatcher . invoke ( ApplicationDispatcher . java : 646 )
at org . apache . catalina . core . ApplicationDispatcher . processRequest ( ApplicationDispatcher . java : 436 )
at org . apache . catalina . core . ApplicationDispatcher . doForward ( ApplicationDispatcher . java : 374 )
at org . apache . catalina . core . ApplicationDispatcher . forward ( ApplicationDispatcher . java : 302 )
at org . apache . struts . chain . commands . servlet . PerformForward . handleAsForward ( PerformForward . java : 113 )
at org . apache . struts . chain . commands . servlet . PerformForward . perform ( PerformForward . java : 96 )
at org . apache . struts . chain . commands . AbstractPerformForward . execute ( AbstractPerformForward . java : 54 )
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 . doGet ( ActionServlet . java : 449 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 617 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 717 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 290 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 233 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 191 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 127 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 102 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 109 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 293 )
at org . apache . coyote . http11 . Http11Processor . process ( Http11Processor . java : 859 )
at org . apache . coyote . http11 . Http11Protocol $Http11ConnectionHandler . process ( Http11Protocol . java : 602 )
at org . apache . tomcat . util . net . JIoEndpoint $Worker . run ( JIoEndpoint . java : 489 )
at java . lang . Thread . run ( Unknown Source )
esse é o formulario motraContato.jsp
<% @ taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
<% @ page language = "java" contentType = "text/html; charset=UTF-8"
pageEncoding = "UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html:html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< title > Altera Contato</ title >
</ head >
< html:errors property = "nome" />
< html:form action = "/alteraContato.do" focus = "contato.nome" >
Nome:
< html:text property = "contato.nome" value = "${contato.nome}" />
< br />
Email:
< html:text property = "contato.email" value = "${contato.email}" />
< br />
Endereço:
< html:text property = "contato.endereco" value = "${contato.endereco}" />
< br />
< html:submit > Enviar dados</ html:submit >
</ html:form >
< body >
</ body >
</ html:html >
O que acha?
jamesfrj 13 de jun. de 2012
Senhores, consegui resolver! Corrigi meu struts-config.xml que estava sem a tag do formulário AlteraContatoForm:
<form-beans>
<form-bean name= "ContatoForm" type= "br.com.caelum.struts.form.ContatoForm" ></form-bean>
<form-bean name= "RemoveContatoForm" type= "br.com.caelum.struts.form.RemoveContatoForm" ></form-bean>
<form-bean name= "MostraContatoForm" type= "br.com.caelum.struts.form.MostraContatoForm" ></form-bean>
<form-bean name= "AlteraContatoForm" type= "br.com.caelum.struts.form.AlteraContatoForm" ></form-bean>
</form-beans>
Corrigi também o código do meu mostraContato.jsp que estava sem o id do contato como hidden:
<html:form action= "/alteraContato.do" focus= "contato.nome" >
<html:hidden property= "contato.id" value= " ${ contato . id } "/ >
Nome:
<html:text property= "contato.nome" value= " ${ contato . nome } "/ >
<br />
Email:
<html:text property= "contato.email" value= " ${ contato . email } "/ >
<br />
Endereço:
<html:text property= "contato.endereco" value= " ${ contato . endereco } "/ >
<br />
<html:submit> Enviar dados</html:submit>
</html:form>
drsmachado 13 de jun. de 2012
jamesfrj:
Senhores, consegui resolver! Corrigi meu struts-config.xml que estava sem a tag do formulário AlteraContatoForm:
<form-beans>
<form-bean name= "ContatoForm" type= "br.com.caelum.struts.form.ContatoForm" ></form-bean>
<form-bean name= "RemoveContatoForm" type= "br.com.caelum.struts.form.RemoveContatoForm" ></form-bean>
<form-bean name= "MostraContatoForm" type= "br.com.caelum.struts.form.MostraContatoForm" ></form-bean>
<form-bean name= "AlteraContatoForm" type= "br.com.caelum.struts.form.AlteraContatoForm" ></form-bean>
</form-beans>
Corrigi também o código do meu mostraContato.jsp que estava sem o id do contato como hidden:
<html:form action= "/alteraContato.do" focus= "contato.nome" >
<html:hidden property= "contato.id" value= " ${ contato . id } "/ >
Nome:
<html:text property= "contato.nome" value= " ${ contato . nome } "/ >
<br />
Email:
<html:text property= "contato.email" value= " ${ contato . email } "/ >
<br />
Endereço:
<html:text property= "contato.endereco" value= " ${ contato . endereco } "/ >
<br />
<html:submit> Enviar dados</html:submit>
</html:form>
Opa, parabéns.
Precisei dar um gás aqui numas coisas, não consegui acompanhar.
Mas é isso, valeu por postar o resultado aí.
jamesfrj 13 de jun. de 2012
Seguem os arquivos que alterei para resolver o problema (podem ajudar outro na mesma situação):
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name= "ContatoForm" type= "br.com.caelum.struts.form.ContatoForm" ></form-bean>
<form-bean name= "RemoveContatoForm" type= "br.com.caelum.struts.form.RemoveContatoForm" ></form-bean>
<form-bean name= "MostraContatoForm" type= "br.com.caelum.struts.form.MostraContatoForm" ></form-bean>
<form-bean name= "AlteraContatoForm" type= "br.com.caelum.struts.form.AlteraContatoForm" ></form-bean>
</form-beans>
<action-mappings>
<action path= "/alteraContato" name= "AlteraContatoForm" type= "br.com.caelum.struts.action.AlteraContatoAction" >
<forward name= "ok" path= "/listaContatos.do" />
</action>
<action path= "/mostraContato" name= "MostraContatoForm" type= "br.com.caelum.struts.action.MostraContatoAction" >
<forward name= "ok" path= "/mostraContato.jsp" />
</action>
<action path= "/mudaIdioma" type= "br.com.caelum.struts.action.MudaIdiomaAction" >
<forward name= "ok" path= "/testa-mensagens.jsp" />
</action>
<action path= "/removeContato" name= "RemoveContatoForm"
type= "br.com.caelum.struts.action.RemoveContatoAction" >
<forward name= "ok" path= "/listaContatos.do" ></forward>
</action>
<action path= "/novoContato" name= "ContatoForm" input= "/novo.jsp"
type= "br.com.caelum.struts.action.AdicionaContatoAction" scope= "request" >
<forward name= "ok" path= "/listaContatos.do" ></forward>
</action>
<action path= "/teste" type= "br.com.caelum.struts.action.TesteSimplesAction" >
<forward name= "ok" path= "/exemplo.jsp" ></forward>
</action>
<action path= "/listaContatos" type= "br.com.caelum.struts.action.ListaContatosAction" >
<forward name= "lista" path= "/lista.jsp" />
<forward name= "vazia" path= "/lista-vazia.jsp" ></forward>
</action>
</action-mappings>
<!-- <message-resources parameter="MessageResources" />-->
</struts-config>
mostraContato.jsp
<% @ taglib uri = "http://struts.apache.org/tags-html" prefix = "html" %>
<% @ page language = "java" contentType = "text/html; charset=UTF-8"
pageEncoding = "UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html:html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< title > Altera Contato</ title >
</ head >
< html:errors property = "nome" />
< html:form action = "/alteraContato.do" focus = "contato.nome" >
< html:hidden property = "contato.id" value = "${contato.id}" />
Nome:
< html:text property = "contato.nome" value = "${contato.nome}" />
< br />
Email:
< html:text property = "contato.email" value = "${contato.email}" />
< br />
Endereço:
< html:text property = "contato.endereco" value = "${contato.endereco}" />
< br />
< html:submit > Enviar dados</ html:submit >
</ html:form >
< body >
</ body >
</ html:html >
Obrigado a todos pela atenção e paciência!
Grande abraço!
jamesfrj 13 de jun. de 2012
Senhores, como marco este tópico como resolvido?
drsmachado 13 de jun. de 2012
Basta editar o tópico original e, no título, incluir [RESOLVIDO] antes do mesmo.
jamesfrj 19 de jun. de 2012
Desculpem a minha ignorância. Não consegui achar a opção para editar o título do meu tópico “Struts 1, apostila da Caelum, dúvidas na action MostraContatoAction” na tela de “Índice dos Fóruns”. Talvez eu esteja sem permissão para ver a opção de editar… Será que o moderador tem acesso para colocar como resolvido?
Desculpem o incômodo…
jamesfrj 20 de jun. de 2012
Pessoal, aprendi aqui como fazer!!
Mais uma vez obrigado!