简体   繁体   中英

struts action mapping action input attribute

I am a noob when it comes to Java and Struts ( I feel like .Net boy in Java world ).

What is the input attribute on the action element used for? So in the example below the input is someinput.jsp.

<action path="/somepath" 
        type="SomeAction" 
        name="SomeForm" 
        scope="session"
        input="someinput.jsp">

If the form bean SomeForm returns validation errors, it will return the page someinput.jsp . To quote the corresponding DTD :

Valid only when "name" is specified. Required if "name" is specified and the input bean returns validation errors. Optional if "name" is specified and the input bean does not return validation errors.

如果在name属性中指定的表单上验证失败,Struts会将用户转发到input属性中指定的页面/操作。

尽管如此,您的行动执行(无论是单个行动单位,还是多个行动单位)也可以指定结果,即SUCCESSFAILUREINPUT

Struts验证器插件将从视图中截取创建的表单bean实例,并在转到控制器之前进行验证,如果数据是针对最终用户验证规则,则在输入属性视图中将错误对象消化,该视图被指定为值

It's for redirection to the jsp in the input attribute. But in your Action controller you need to specify mapping.getInputForward() instead of mapping.findForward().

Struts-config file:

<action input="test.jsp"
        name="testActionForm"
        path="/test" 
        scope="session"      type="package.TestActionController">
</action>

Action Controller:

public ActionForward doMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        return mapping.getInputForward();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM