Struts2 File Upload doesn't work on Internet-E

2019-08-29 12:11发布

问题:

I am having issue with Struts 2 file upload for Word file(.docx, .doc) in Internet Explorer. It works fine in Chrome and Firefox, but I am not sure what I am missing for IE. I am using IE9. I appreciate your advice.

<action name="saveOrUpdateUser" method="saveOrUpdate"
            class="com.adaptivsol.action.UsersAction">
    <interceptor-ref name="defaultStack">
        <param name="fileUpload.maximumSize">104857600</param>
        <param name="allowedTypes">
                text/plain,                 
                application/word,
                application/msword,
                application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
                application/vnd.openxmlformats-officedocument.wordprocessingml.document
        </param>
        <param name="allowedExtensions">doc,docx,txt</param>
    </interceptor-ref>
    <result name="success">./pages/login/register.jsp</result>
    <result name="input">./pages/login/register.jsp</result>
    <result name="error">./pages/login/register.jsp</result>
</action>

回答1:

Your parameters are wrong, the fileUpload. prefix is missing in two of them, they need to be:

<param name="fileUpload.allowedTypes">
    text/plain,                 
    application/word,
    application/msword,
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
</param>
<param name="fileUpload.allowedExtensions">doc,docx,txt</param>

By the way, set devMode to true in struts.xml, and post here the logs where the file upload stop working. We need to see an error, a warning, a message, something to understand what's wrong.

Also in your JSP add actionerrors, actionmessages and fielderrors printing capabilities, and report here the message you get.