javahttp-redirectfile-uploadstruts2interceptorstack

No chain redirection with Jakarta in Struts2 (Uploading big files)


I am making a new project with struts2. All fine, but i dont know what is happening in this case.

The project have chain redirections when the business logic fails, its return to the last JSP (the last action), to reload succesfully all the page without programming work (its reload the old request too).

Anyway, when Jakarta detects that the user is trying to upload a big file (the default configuration is 20 MB), the logic of the action knows that and forces a chain redirection to the last action.

I debug this logic. I have an interceptor that do several things, in the typical line:

result = invocation.invoke();

When Jakarta forces the chain redirection, the interceptor capture this new request, but doesnt reach the action with the invoke method.

I dont know why is this happening. When the same action forces the same chain redirection, because other validations like the FileUpload interceptor of struts2 or owns validations, all work good.

I solved in the program avoiding the redirection, but i want to know why i cant use my normal mode.

Some parts of the struts.xml:

<constant name="struts.multipart.maxSize" value="20971520" />

The result of MostrarResumenSubsanacion is the next action if all validatios are good.

The result of MostrarRespuestaSubsanaciones is the last action if some validation fail.

The result of ErrorJakarta is the new line to solve the problem.

<action name="MostrarResumenSubsanacion" class="struts.expedientes.subsanaciones.MostrarResumenSubsanacion">
    <param name="conseguirConexion">SI</param>
    <param name="seguimiento">SI</param>
    <interceptor-ref name="interceptorFileStack"></interceptor-ref>
    <result name="MostrarRespuestaSubsanaciones" type="chain">MostrarRespuestaSubsanaciones</result>
    <result name="ErrorJakarta">/forms/struts/expedientes/subsanaciones/ventanaRespuestaSubsanacion.jsp</result>
    <result name="MostrarResumenSubsanacion">/forms/struts/expedientes/comun/ventanaResumen.jsp</result>
</action>


<action name="MostrarRespuestaSubsanaciones" class="struts.expedientes.subsanaciones.MostrarRespuestaSubsanaciones">
    <param name="conseguirConexion">SI</param>
    <param name="seguimiento">SI</param>
    <interceptor-ref name="interceptorBaseStack"></interceptor-ref>
    <result name="MostrarVentanaSubsanaciones">/forms/struts/expedientes/subsanaciones/ventanaRespuestaSubsanacion.jsp</result>
    <result name="input">/forms/struts/expedientes/subsanaciones/ventanaRespuestaSubsanacion.jsp</result>
</action>

Solution

    1. The usage of the Chain result type is discouraged; try using redirectAction (or dispatcher) instead.

    2. Each request in Struts2:

      • passes through a stack of interceptor,
      • eventually reach the Action,
      • then is filtered backward through the same interceptor stack, running the code after the line invocation.invoke(); (if any);
    3. If something bad (but recoverable) happens, an INPUT result is thrown; otherwise, if something very bad happens, an exception is thrown.

    Then if you are hitting the 20MB threshold, an INPUT result is returned somewhere, instead of the normal (bad) chaining process.

    It should be easier to spoil what exactly is going on by looking at the definition of both your interceptor stacks, but with the above informations you should be able to find the problem faster than updating the question.