What is 'eating' my uploadFile before my POST servlet can process it?

无人久伴 提交于 2019-12-02 07:01:06
Andrea Ligios

If you are using Struts2, you will probably have this setting in web.xml:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Since the url-pattern is /*, it means that every request is intercepted by the StrutsPrepareAndExecuteFilter (usually called Filter Dispatcher, that was also the old filter name, in Struts versions before 2.1.8).

If you call an action, this is perfect. If you call a servlet, a web-service, or something else, this is problematic, because Struts Filter should run for actions only.

To exclude a particular url (or a particular pattern) from being intercepted by the filter, you need to use the constant struts.action.excludePattern in struts.xml, as described in

Then put in struts.xml

<constant name="struts.action.excludePattern" value="/YourServlet"/>

And it should work.


At this point, I'm curious to know why are you using Struts2 without exploiting the great inbuilt File Upload functionality, that is explained in

and that can work with other upload-oriented frameworks with minor adjustments, like demonstrated in:

I don't know the plugin you're using, but in your case the first (and probably only) problem I see is the name of the parameter sent out:

uploadDoc_0__frm_if

should be unnumbered, and it'll still need a mixed CamelCase / Snake_case approach in your variable name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!