Advertisement

01.04.2005 at 09:23AM PST, ID: 21261386
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

newbie action forwarding problem in struts

Asked by fnuzbit in Java Server Pages (JSP), Plug Ins

Tags: , ,

I am setting up a struts project and have been following an online tutorial at: http://javaboutique.internet.com/tutorials/Struts/
to get started. But my action forwarding is not working. When the submit button is pressed on the submit.jsp page (all code is below) submit.do appears in the browser but a blank page comes up - it should be reloading the same page with the updated javabean info. Any ideas anyone?
________________________________________________

submit.jsp
__________

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" 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>

______________________________________________

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">
<struts-config>

<!-- ============================================ Data Source Configuration -->


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

    <form-beans>
    <form-bean      name="submitForm"
                    type="showcase.SubmitForm"/>
    </form-beans>


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

    <global-exceptions>

    </global-exceptions>


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

    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="welcome"
            path="/Welcome.do"/>
    </global-forwards>


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

    <action-mappings>
            <!-- Default "Welcome" action -->
            <!-- Forwards to Welcome.jsp -->
        <action
            path="/Welcome"
            forward="/Welcome.jsp"/>

          <action   path="/submit"
            type="showcase.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 -->


    <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>

______________________________________________

SubmitAction.java
_________________

package showcase;

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"));
  }
}

________________________________________________

SubmitAction.java
_________________

package showcase;

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

public final class SubmitForm extends ActionForm {

  /* Last Name */
  private String lastName = "Alfresco"; // 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;
  }

}
Start Free Trial
 
Loading Advertisement...
 
[+][-]01.04.2005 at 10:35AM PST, ID: 12954885

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.04.2005 at 10:47AM PST, ID: 12955017

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Server Pages (JSP), Plug Ins
Tags: dtd, forward, tiles
Sign Up Now!
Solution Provided By: kiranhk
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.04.2005 at 10:30PM PST, ID: 12959769

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.25.2005 at 09:55AM PST, ID: 13405288

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.06.2005 at 03:33PM PDT, ID: 13722094

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.16.2005 at 06:15AM PDT, ID: 14230740

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.20.2005 at 03:08AM PDT, ID: 14255368

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32