posted 15 years ago
The HTML input type="file" element has an 'accept' attribute which is specified by the W3 HTML specification as optional. You can define in there the content types (mime types) which are to be displayed in the browse dialog only. Unfortunately a lot of webbrowsers doesn't support it. As far now only Opera, which very strictly follows the W3 HTML spec, supports it.
To fullfill this requirement, you need to validate it at the server side at any way. You can use ServletContext#getMimeType() for it to validate the file extension against the mime mapping configuration of the appserver in question. Alternatively you can use URLConnection#guessContentTypeFromName() to validate the file extension against the file type configuration of the underlying operating system.