我有一个动作映射,它似乎只映射到其中一个路径(UnderAge),我的动作类中有一些逻辑,我不确定我是否在我的路径中犯了一个愚蠢的编程错误动作类或如果我的动作映射错误。 动作映射如下:
<action
path="/AgeCheck"
type="coreservlets.CheckAgeAppAction"
name="CheckAgeAppForm"
input="/welcome.jsp">
<forward name="OverAge" path="/OverAge.jsp" />
<forward name="UnderAge" path="/UnderAge.jsp" />
</action>
我的动作课在这里:
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");
}
}
我希望用户输入他们的姓名和年龄,操作应该决定OverAge或UnderAge路径,具体取决于用户在jsp页面上输入的年龄(> 18 = OverAge,&lt; 18 = UnderAge)。 行动表格只是因为我在那里犯了错误:
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;
}
}