Erro Struts ta me tirando o juizo

2 respostas
dead_thinker

Galera, fazendo esse tutorial aqui, do jeitinho como está http://javaboutique.internet.com/tutorials/Struts/ não consegui visualizar o submit.jsp no final, dá erro, diz que não pode criar meu bean. Já fucei pra caramba no struts-config.xml e na classe mas n detectei erro.

Me ajudem. :cry:

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<!--
     This is a blank Struts configuration file with an example
     welcome action/page and other commented sample elements.

     Tiles and the Struts Validator are configured using the factory defaults
     and are ready-to-use.

     NOTE: If you have a generator tool to create the corresponding Java classes
     for you, you could include the details in the "form-bean" declarations.
     Otherwise, you would only define the "form-bean" element itself, with the
     corresponding "name" and "type" attributes, as shown here.
-->


<struts-config>


<!-- ================================================ Form Bean Definitions -->

    <form-beans>

	    <form-bean      name="submitForm"
	                    type="hansen.playground.SubmitForm"/>

    </form-beans>


<!-- ========================================= Global Exception Definitions -->

    <global-exceptions>
    </global-exceptions>


<!-- =========================================== Global Forward Definitions -->

    <global-forwards>

        <forward
            name="welcome"
            path="/Welcome.do"/>

    </global-forwards>


<!-- =========================================== Action Mapping Definitions -->

    <action-mappings>

        <action
            path="/Welcome"
            forward="/pages/Welcome.jsp"/>


    <action   path="/submit"
              type="hansen.playground.SubmitAction"
              name="submitForm"
              input="/submit.jsp"
              scope="request">
    <forward name="success" path="/submit.jsp"/>          
    <forward name="failure" path="/submit.jsp"/>          
    </action>

    </action-mappings>


<!-- ============================================= Controller Configuration -->

    <controller
       processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>


<!-- ======================================== Message Resources Definitions -->

    <message-resources parameter="MessageResources" />


<!-- =============================================== Plug Ins Configuration -->

  <!-- ======================================================= Tiles plugin -->
  <!--
     This plugin initialize Tiles definition factory. This later can takes some
	 parameters explained here after. The plugin first read parameters from
	 web.xml, thenoverload them with parameters defined here. All parameters
	 are optional.
     The plugin should be declared in each struts-config file.
       - definitions-config: (optional)
            Specify configuration file names. There can be several comma
		    separated file names (default: ?? )
       - moduleAware: (optional - struts1.1)
            Specify if the Tiles definition factory is module aware. If true
            (default), there will be one factory for each Struts module.
			If false, there will be one common factory for all module. In this
            later case, it is still needed to declare one plugin per module.
            The factory will be initialized with parameters found in the first
            initialized plugin (generally the one associated with the default
            module).
			  true : One factory per module. (default)
			  false : one single shared factory for all modules
	   - definitions-parser-validate: (optional)
	        Specify if xml parser should validate the Tiles configuration file.
			  true : validate. DTD should be specified in file header (default)
			  false : no validation

	  Paths found in Tiles definitions are relative to the main context.
  -->

    <plug-in className="org.apache.struts.tiles.TilesPlugin" >

      <!-- Path to XML definition file -->
      <set-property property="definitions-config"
                       value="/WEB-INF/tiles-defs.xml" />
      <!-- Set Module-awareness to true -->
      <set-property property="moduleAware" value="true" />
    </plug-in>


  <!-- =================================================== Validator plugin -->

  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property
        property="pathnames"
        value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
  </plug-in>

</struts-config>

submit.jsp

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

<html>
<head><title>Submit example</title></head>
<body>

<h3>Example Submit Page</h3>

<html:errors/>

<html:form action="submit.do">
Last Name: <html:text property="lastName"/><br>
Address:   <html:textarea property="address"/><br>
Sex:       <html:radio property="sex" value="M"/>Male 
           <html:radio property="sex" value="F"/>Female<br>
Married:   <html:checkbox property="married"/><br>
Age:       <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><br>
           <html:submit/>
</html:form>

</body>
</html>

classe SubmitForm.java

package hansen.playground;

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

public final class SubmitForm extends ActionForm {

  /* Last Name */
  private String lastName = "Hansen"; // default value
  public String getLastName() {
    return (this.lastName);
  }
  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  /* Address */
  private String address = "Sabino Monte";
  public String getAddress() {
    return (this.address);
  }
  public void setAddress(String address) {
    this.address = address;
  }

  /* Sex */
  private String sex = "M";
  public String getSex() {
    return (this.sex);
  }
  public void setSex(String sex) {
    this.sex = sex;
  }

  /* Married status */
  private String married = "Almost";
  public String getMarried() {
    return (this.married);
  }
  public void setMarried(String married) {
    this.married = married;
  }

  /* Age */
  private String age = "22";
  public String getAge() {
    return (this.age);
  }
  public void setAge(String age) {
    this.age = age;
  }

}

2 Respostas

Abdon

Tu não postou a classe hansen.playground.SubmitAction, sera que ela não esta faltando?

dead_thinker

Ta faltando não, chequei isso tb :smiley:

Vo postar o codigo das 2 classes :stuck_out_tongue:

package hansen.playground;

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

public final class SubmitForm extends ActionForm {

  /* Last Name */
  private String lastName = "Hansen"; // default value
  public String getLastName() {
    return (this.lastName);
  }
  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  /* Address */
  private String address = null;
  public String getAddress() {
    return (this.address);
  }
  public void setAddress(String address) {
    this.address = address;
  }

  /* Sex */
  private String sex = null;
  public String getSex() {
    return (this.sex);
  }
  public void setSex(String sex) {
    this.sex = sex;
  }

  /* Married status */
  private String married = null;
  public String getMarried() {
    return (this.married);
  }
  public void setMarried(String married) {
    this.married = married;
  }

  /* Age */
  private String age = null;
  public String getAge() {
    return (this.age);
  }
  public void setAge(String age) {
    this.age = age;
  }

}

===============================

package hansen.playground;

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

public final class SubmitAction extends Action {

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

    SubmitForm f = (SubmitForm) form; // get the form bean
    // and take the last name value
    String lastName = f.getLastName(); 
    // Translate the name to upper case 
    //and save it in the request object 
    request.setAttribute("lastName", lastName.toUpperCase());
    
    // Forward control to the specified success target
    return (mapping.findForward("success"));
  }
}
Criado 22 de maio de 2006
Ultima resposta 22 de mai. de 2006
Respostas 2
Participantes 2