22

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">
rabs
  • 1,807
  • 3
  • 18
  • 29

5 Answers5

31

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.

zb226
  • 9,586
  • 6
  • 49
  • 79
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
4

Struts will forward the user to the page/action specified in the input attribute if validation fails on the form specified in the name attribute.

highlycaffeinated
  • 19,729
  • 9
  • 60
  • 91
1

Notwithstanding the above, it is also possible in your action execution (whether it is a single unit of action, or multiple units of action), to specify the result, i.e. SUCCESS, FAILURE, or INPUT.

Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215
0

Struts validator plug-in will intecept the created form bean instance from the view and does validation before going to controller and if the data is against the end-user validation rules then errors object is digested in input attribute view which is specified as a value

Nagappa L M
  • 1,452
  • 4
  • 20
  • 33
0

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();
}
Ahmed MANSOUR
  • 2,369
  • 2
  • 27
  • 35