you're reading...

Multipart request handling with Struts and Spring

Struts 1.x has inbuilt mechanisms to handle multi part posts (file uploads). By default it uses Apache Commons Fileupload. In the application I was working on we used Struts as the MVC framework, but Spring to do pretty much everything else. Springs, Struts integration module was extensively used, and we were using Spring’s SpringBindingActionForm for almost all action form handling. On the same lines, we wanted to use Spring’s Multipart file support (MultipartFile).

Unfortunately, by the time request would reach Spring’s ServletRequestDataBinder, Commons Fileupload would have already handled the multi part request and wrapped it. And there was no available documentation on the Struts website to disable this feature. A little bit of hacking struts code did reveal a pretty easy solution, just disable multipart handling in the init parameters of the struts servlet in the web.xml of your application:

<!-- Struts Action <span class="hiddenSpellError" pre="Action ">Servlet</span> -->
		The Struts Config File
	<!-- The following parameter disables multi part handling by struts -->
		<description>Disable Struts Multipart Handling</description>

This has been tested on Struts 1.3.8, but should work on other 1.x versions too.


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Random Musings

Random Musings is a collection of my personal thoughts, opinions, views and anything else that I find interesting. The views posted here are mine and may not necessarily reflect the views of MindTree Limited (my employer).
%d bloggers like this: