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