File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Restricting Type of file being uploaded Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Restricting Type of file being uploaded" Watch "Restricting Type of file being uploaded" New topic

Restricting Type of file being uploaded

Vikram Virk

Joined: Mar 13, 2006
Posts: 8
Please suggest some ways to restrict type and size of file being uploaded through JSP.I want only image file(gif,jpeg,bitmap..).My action class is

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {

NewsForm newsForm = (NewsForm) form;
FormFile myFile=null;
myFile = newsForm.getTheFile();

String fileName = myFile.getFileName();

InputStream uploadInStream = myFile.getInputStream();

FileOutputStream fOut = new FileOutputStream("d:\\temp\\"
+ fileName);
int c=0;
while (( != -1) {
} // while

catch(FileNotFoundException fnfe){

I agree. Here's the link:
subject: Restricting Type of file being uploaded
It's not a secret anymore!