1. Implement the PersonalDataAction class
    1. Add necessary imports import javax.servlet.ServletContext;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      import org.apache.struts.action.Action;
      import org.apache.struts.action.ActionMapping;
      import org.apache.struts.action.ActionForm;
      import org.apache.struts.action.ActionForward;
      import org.apache.struts.action.DynaActionForm;
    2. Our class needs to extend action public class PersonalDataAction extends Action
    3. Implement the Struts Action execute method. This method is what is called when your action is requested from the browser.
      Signature of the execute method: public ActionForward execute(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response)
      NOTE: For more Struts class details, see the struts API which is included in the Zip file downloaded.
    4. Get form bean data from our PersonalData class
      1. Cast the form to PersonalData
      2. In a full blown application, this is where the data would be stored to the database or otherwised processed. PersonalData pd = (PersonalData) form;
    5. The Struts ActionForward tells the Struts controller of where to proceed to. if (form != null) {
          return (mapping.findForward(Constants.SUCCESS_KEY));
      else {
          return (mapping.findForward(Constants.FAILURE_KEY));
      }
  2. Implement our form page to populate the PersonalData bean
    1. Right click pages under WebRoot, Select New => File
    2. Name the file PersonalData.jsp, and Click Finish
    3. Create two more files called Results.jsp and Error.jsp
  3. Implement PersonalData.jsp <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
    <%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>

    <html:html>
    <head>
        <title>Form for entering Personal Data</title>
        <html:base />
    </head>

    <body>
        <html:form method="post" action="/Confirmation">
            <table border="0">
                <tr>
                    <td width="50">
                        <bean:message key="personalData.add.firstname"/>
                    </td>
                    <td>
                        <html:text property = "firstname" size = "30"/>
                    </td>
                </tr>
                <tr>
                    <td width="35">
                        <bean:message key="personalData.add.lastname"/>
                    </td>
                    <td>
                        <html:text property="lastname" size="30"/>
                    </td>
                </tr>
                <tr>
                    <td width="35">
                        <bean:message key="personalData.add.address"/>
                    </td>
                    <td>
                        <html:text property="address" size="80"/>
                    </td>
                </tr>
                <tr>
                    <td width="35">
                        <bean:message key="personalData.add.city"/>
                    </td>
                    <td>
                        <html:text property="city" size="30"/>
                    </td>
                </tr>
                <tr>
                    <td width="35">
                        <bean:message key="personalData.add.state"/>
                    </td>
                    <td>
                        <html:text property="state" size="30"/>
                    </td>
                </tr>
            </table>

            <br />

            <html:submit>
                <bean:message key="personalData.add.submit"/>
            </html:submit>

        </html:form>

    </body>
    </html:html>
  4. Now we need to create the ApplicationResources.properties file
    1. From the main project expand the WebRoot tree
    2. Select and expand the WEB-INF folder
    3. Select and expand the src folder
    4. Rename the MessageResources.properties file to ApplicationResources.properties
      1. At the end of the file add in the following logic and save the file # -- Personal Data
        personalData.add.firstname = First Name
        personalData.add.lastname = Last Name
        personalData.add.address = Address
        personalData.add.city = City
        personalData.add.state = State
        personalData.add.submit = Submit
      2. Now we need to manually put this file into: C:\Tomcat5.0\webapps\BasicStrutsExample\WEB-INF\classes
      3. Navigate to: C:\eclipse\workspace\BasicStrutsExample\WebRoot\WEB-INF\src
      4. Copy the file
      5. Navigate to: C:\Tomcat5.0\webapps\BasicStrutsExample\WEB-INF\classes
      6. Paste the file here
  5. Now we need to modify the struts-config file
    1. From the main project expand the WebRoot tree
    2. Select and expand the WEB-INF folder
    3. Select and double click the struts-config.xml file
    4. Under the Form Bean Definitions add a new Form Bean
      1. Name it PersonalDataBean
      2. Have it’s type equal your package and the bean class
      3. In our case it would look something like: <form-bean name="personalDataBean" type="pdata.PersonalData">
      4. Now add in all of the other properties that we had
      5. Overall the Form Bean should look like the following: <form-bean name="personalDataBean" type="pdata.PersonalData">
            <form-property name="firstname" type="java.lang.String" />
            <form-property name="lastname" type="java.lang.String" />
            <form-property name="address" type="java.lang.String" />
            <form-property name="city" type="java.lang.String" />
            <form-property name="state" type="java.lang.String" />
        </form-bean>
    5. Now we need to modify the Action Mappings Definitions
      1. Have the Action Path directed to the pages/PersonalData.jsp if any url address ends with /PersonalData. It should look like the following: <action path="/PersonalData" forward="/pages/PersonalData.jsp" />
      2. Now, add an action. Have it directed to the Results page or the Error page if there is a problem. It might look something like this: <action
            path="/Results"
            type="pdata.PersonalDataAction"
            scope="request"
            name="personalDataBean"
            input="/pages/PersonalData.jsp">
                <forward name="success" path="/pages/Results.jsp" />
                <forward name="failure" path="/pages/Error.jsp" />
        </action>
      3. Under Message Resources Definitions add the following logic: <message-resources parameter="ApplicationResources" null = "false" />
      4. Save and close the file
Page 1 Page 2 Page 4