I am using Struts2 file upload ( http://struts.apache.org/2.2.1/docs/file-upload.html ) to upload a CSV or Excel 开发者_StackOverflow中文版file which I will parse.
The MIME type is being set as application/vnd.ms-excel
for both file types and I want to make the CSVs text/csv
. This is so I can just check the MIME type and call the corresponding parser.
I've tried adding the following to Tomcat's web.xml but it has had no effect:
<mime-mapping>
<extension>csv</extension>
<mime-type>text/csv</mime-type>
</mime-mapping>
Just putting it out there maybe not a universal solution but you should be able to create a file upload action of the form (I think the mime type is determined by the application server so is outside of struts.)
<package name="upload" extends="struts-default">
<action name="*.*" class="someClass">
<param name="filePrefix">{1}</param>
<param name="fileExtension">{2}</param>
<action name="*.*" class="someClass">
</package>
Not tested then you could call it with http://address_and_port/context_root/upload/myFile.jpg
Not as encompassing as the mime type but if you're only doing a handful of files it'll work and perhaps its a trick worth remembering (you can even have an action with slashes and parse out the values between them as parameters).
PS: I don't know if escaping is required for dots...
精彩评论