0

I have an action mapping which only seems to map to one of the paths (UnderAge), there is some logic in my action class , I'm unsure if I've made a silly programming mistake in my action class or if I have the action-mapping wrong . Action mapping is as follows:

<action
            path="/AgeCheck"
            type="coreservlets.CheckAgeAppAction"
            name="CheckAgeAppForm"
            input="/welcome.jsp">   

            <forward name="OverAge" path="/OverAge.jsp" />
            <forward name="UnderAge" path="/UnderAge.jsp" />
            </action>

And my action class is here :

package coreservlets;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public int age;

public class CheckAgeAppAction extends Action {
    public ActionForward execute(
              ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response) throws ServletException{


        coreservlets.CheckAgeAppForm CheckAgeAppForm = (CheckAgeAppForm) form;
//      String age = CheckAgeAppForm.getAge();
        age = Integer.parseInt(CheckAgeAppForm.getAge());
        System.out.println("int is : " + num);

        if (age > 17){
            return mapping.findForward("OverAge");

        }
        else{
            return mapping.findForward("UnderAge");
        }



}

I want the user to enter their name and age, the action should decide either the OverAge or UnderAge path, depending on the age the user entered(>18 = OverAge, <18 = UnderAge) on the jsp page. The action form is here just incase I've made an error there :

package coreservlets;

import org.apache.struts.action.*;

public class CheckAgeAppForm extends ActionForm {

    private static final long serialVersionUID = 1L;
    private String firstName= "Enter Name";
    private String age = "Enter Age";

    public String getFirstName(){
        return firstName;
    }
    public String getAge(){
        return age;
    }
    public void setFirstName(String name){
        this.firstName= name;
    }
    public void setAge(String age){
        this.age = age;

    }



}
DerekReilly1990
  • 49
  • 2
  • 10
  • I'm not clear on what the question is. If nothing else, you have two forwards with the same name, `name="UnderAge"`. – Dave Newton Apr 25 '16 at 12:21
  • That was a mistake I've Since corrected sorry..Basically i have an welcome.jsp page which asks the user to enter their name and age, on submit this passes to the checkAgeAppAction/CheckAgeAppForm. In my CheckAgeAppAction i have an if/else statement, if the users age is >17 i want it to forward to OverAge.jsp, otherwise i want it to forward to UnderAge.jsp..Currently it will only forward to UnderAge.jsp, i dont know why or how i should do this. thanks – DerekReilly1990 Apr 25 '16 at 12:30
  • Check your assumptions and your data: debug or log what's happening. – Dave Newton Apr 25 '16 at 12:46
  • This issue has been resolved and was due to a mix of struts versions between the different files, due to copying files from another project. – DerekReilly1990 Apr 27 '16 at 13:47

0 Answers0