Erro no Struts

2 respostas
R

e ai pessoal blz, estou tentando criar um exemplo bem basico aqui usando o Struts, so que esta dando o seguinte erro quando eu mando rodar

type Exception report 

message 

description The server encountered an internal error () that prevented it from fulfilling this request. 

exception 

javax.servlet.ServletException: Cannot retrieve definition for form bean cadastroForm 
   org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848) 
   org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781) 
   org.apache.jsp.pages.cadastro_jsp._jspService(org.apache.jsp.pages.cadastro_jsp:118) 
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) 
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) 
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) 
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) 
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 


root cause 

javax.servlet.jsp.JspException: Cannot retrieve definition for form bean cadastroForm 
   org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:831) 
   org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:506) 
   org.apache.jsp.pages.cadastro_jsp._jspx_meth_html_form_0(org.apache.jsp.pages.cadastro_jsp:151) 
   org.apache.jsp.pages.cadastro_jsp._jspService(org.apache.jsp.pages.cadastro_jsp:105) 
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) 
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322) 
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) 
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) 
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

bem a baixo vou demostra as minhas classe e a pagina jsp
cadastro.jsp

<%@ taglib uri="/tags/struts-bean" prefix="bean" %> 
<%@ taglib uri="/tags/struts-html" prefix="html" %> 
<%@ taglib uri="/tags/struts-logic" prefix="logic" %> 

<html> 
<head> 
<title>Cadastro Cliente</title> 
</head> 
<body> 

<h3>Exemplo de Cadastro de Cliente</h3> 

<html:errors /> 

<html:form action="cadastro.do"> 

   <table bgcolor=lightgrey> 
      <tr> 
         <td>Last Name:</td> 
         <td><html:text property="lastName" /></td> 
      </tr> 

      <tr> 
         <td>Address:</td> 
         <td><html:textarea property="address" /></td> 
      </tr> 

      <tr> 
         <td>Sex:</td> 
         <td><html:radio property="sex" value="M" />Male <html:radio 
            property="sex" value="F" />Female</td> 

      </tr> 

      <tr> 
         <td>Married:</td> 
         <td><html:checkbox property="married" /></td> 
      </tr> 

      <tr> 
         <td>Children:</td> 
         <td><html:multibox property="children" value="boys" />boy(s) <html:multibox 
            property="children" value="girls" />girl(s)</td> 
      </tr> 

      <tr> 
         <td>Age:</td> 
         <td><html:select property="age"> 
            <html:option value="a">0-19</html:option> 
            <html:option value="b">20-49</html:option> 
            <html:option value="c">50-</html:option> 
         </html:select></td> 
      </tr> 

      <tr> 
         <td>Interests:</td> 
         <td><html:select multiple="true" size="3" property="interests"> 
            <html:option value="photo">Photography</html:option> 
            <html:option value="it">Computers</html:option> 
            <html:option value="music">Music</html:option> 
         </html:select></td> 
      </tr> 

      <tr> 
         <td><html:submit /></td> 
      </tr> 
   </table> 

</html:form> 

</body> 
</html>

CadastroAction.java

package br.ufrj.nce.tees4.exemploStruts.action; 

import javax.servlet.http.*; 
import org.apache.struts.action.*; 

import br.ufrj.nce.tees4.exemploStruts.form.CadastroForm; 

public final class CadastroAction extends Action { 

   public ActionForward execute( 
      ActionMapping mapping, 
      ActionForm form, 
      HttpServletRequest request, 
      HttpServletResponse response) { 

      CadastroForm f = (CadastroForm) form; // get the form bean 
      String[] interests = f.getInterests(); 

      /* 
      ActionErrors errors = new ActionErrors(); 
      if (interests == null || interests.length == 0) 
         errors.add("interests", new ActionError("error.interests")); 

      if (!errors.isEmpty()) { 
         saveErrors(request, errors); 
         // Return to same page 
         return (new ActionForward(mapping.getInput())); 
      } 
      */ 

      // Forward control to the specified success target 
      return (mapping.findForward("success")); 
   } 
}

CadastroForm.java

package br.ufrj.nce.tees4.exemploStruts.form; 

import javax.servlet.http.HttpServletRequest; 
import org.apache.struts.action.*; 
import org.apache.struts.validator.*; 

public final class CadastroForm extends ValidatorForm { 

   private String lastName = null; 
   private String address = null; 
   private String sex = null; 
   private String married = null; 
   private String age = null; 
   private String[] children = null; 
   private String[] interests = null; 

   public String getLastName() { 
      return (this.lastName); 
   } 
   public void setLastName(String lastName) { 
      this.lastName = lastName; 
   } 

   public String getAddress() { 
      return (this.address); 
   } 
   public void setAddress(String address) { 
      this.address = address; 
   } 

   public String getSex() { 
      return (this.sex); 
   } 
   public void setSex(String sex) { 
      this.sex = sex; 
   } 

   public String getMarried() { 
      return (this.married); 
   } 
   public void setMarried(String married) { 
      this.married = married; 
   } 

   public String getAge() { 
      return (this.age); 
   } 
   public void setAge(String age) { 
      this.age = age; 
   } 

   public String[] getChildren() { 
      return (this.children); 
   } 
   public void setChildren(String[] children) { 
      this.children = children; 
   } 

   public String[] getInterests() { 
      return (this.interests); 
   } 
   public void setInterests(String[] interests) { 
      this.interests = interests; 
   } 

/* 
   public ActionErrors validate( 
      ActionMapping mapping, 
      HttpServletRequest request) { 

      ActionErrors errors = super.validate(mapping, request); 
      if (errors == null) 
         errors = new ActionErrors(); 

      if (lastName == null || lastName.equals("")) { 
         errors.add("lastName", new ActionError("error.lastname")); 
      } 
      return errors; 
   } 
*/ 
}

Struts-config

<!-- ==================== Form Bean Definitions --> 
<form-beans> 
      <form-bean name="CadastroForm" type="br.ufrj.nce.tees4.exemploStruts.form.CadastroForm" /> 
         <form-property name="lastName" type="java.lang.String" /> 
         <form-property name="address" type="java.lang.String" /> 
         <form-property name="sex" type="java.lang.String" /> 
         <form-property name="married" type="java.lang.String" /> 
         <form-property name="children" type="java.lang.String[]" /> 
         <form-property name="age" type="java.lang.String" /> 
         <form-property name="interests" type="java.lang.String[]" /> 
      </form-bean> 

   </form-beans> 

<!-- ==================== Action Mapping Definitions --> 
<action 
         path="/cadastro" 
         type="br.ufrj.nce.tees4.exemploStruts.action.CadastroAction" 
         name="cadastroForm" 
         input="/pages/cadastro.jsp" 
         scope="request" 
      > 
         <forward name="success" path="/pages/cadastro.jsp" /> 
         <forward name="failure" path="/pages/cadastro.jsp" /> 
      </action>

validation.xml

<form name="cadastroForm"> 
         <field property="lastName" depends="required"> 
            <arg0 key="validateform.lastname" /> 
         </field> 
         <field property="address" depends="required"> 
            <arg0 key="validateform.address" /> 
         </field> 
         <field property="sex" depends="required"> 
            <arg0 key="validateform.sex" /> 
         </field> 
         <field property="children" depends="required"> 
            <arg0 key="validateform.children" /> 
         </field> 
         <field property="age" depends="required"> 
            <arg0 key="validateform.age" /> 
         </field> 
         <field property="interests" depends="required"> 
            <arg0 key="validateform.interests" /> 
         </field> 
      </form>

ai esta se alguem puder me ajudar
valeu pessoal

2 Respostas

bonfarj

Na vc colocou CadastroForm, com “C”, e na está cadastroForm, com “c”.

Dê uma olhada e veja se é isso mesmo. Espero ter ajudado. :wink:

R

bonfarj:
Na vc colocou CadastroForm, com “C”, e na está cadastroForm, com “c”.

Dê uma olhada e veja se é isso mesmo. Espero ter ajudado. :wink:


esse deu certo valeu pela ajuda

Criado 21 de agosto de 2006
Ultima resposta 22 de ago. de 2006
Respostas 2
Participantes 2