I am using Struts 2.3.24.1 and after switching to the jakarta-stream
implementation because of the bug mentioned here, I discovered a new error when the file upload field in my form is empty.
My form looks like this (abridged):
<s:form enctype="multipart/form-data" method="POST" action="persistAddNote" id="noteForm">
<s:token/>
<s:file name="fileUpload" size="79"/>
<s:if test="hasActionErrors()">
<s:property value="%{#request.uploadError}" escape="false"/>
</s:if>
<s:submit cssClass="buttonFormat" value="Save"
onclick="javascript: disableButtons(); document.noteForm.submit();"/>
</s:form>
The persistAddNote
action is configured as follows:
<action name="persistAddNote" class="my.example.action.PersistNoteAction">
<param name="parameter">my.example.encoder.Latin1ToLatin9Encoder</param>
<interceptor-ref name="tokenSession"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<exception-mapping name="notes.error.filesize"
exception="my.example.exception.UploadFileSizeException"
result="/notes/error.jsp"/>
<result name="input">/notes/addnote.jsp</result>
<result name="added">/notes/newnoteok.jsp</result>
<result name="novalidaction">/notes/noValidActionError.jsp</result>
</action>
The error occurs in the JakartaStreamMultiPartRequest.createTemporaryFile(String, String)
method because no filename is set. This is to be expected since the file upload field is not required. I tried debugging the Struts code but it looks as if the multipart/form-data
enctype always triggers the creation of a temporary file. The error is gone when I switch back to the standard jakarta
implementation in the struts.properties
but that brings back the issue I mentioned above.
Does anyone have an idea how to fix this issue?