I need to restrict users from attaching files with some extensions for e.g.: bat,exe,bin etc..
For this i believe i will need to write a servlet filter . I am new to servlets ,can someone please guide me how i can achieve this ?
Is using Servlet filter a correct approach ?
Any help highly appreciated.
Please let me know if any other information is needed from me.
Well, you can always use a servlet filter to add some kind of validation that runs before the code for your servlet. It might or might not be the way to go depending on how are your structuring your application. It is your architectural call.
The way to implement a servlet filter is really simple, you can take a look at http://www.oracle.com/technetwork/java/filters-137243.html
Regarding validating the input extension. How trusted do you need that validation to be? Please keep in mind that the user might always play with the extensions before uploading the file. If you are relaxed about it you might implement it in a really simple way, just check the
Content-Typeheader out of your request for valid mime types.If you need a more solid validation you will need to use something more like Mime-Utils or something like that. Check Getting A File's Mime Type In Java