Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Restricting Type of file being uploaded  RSS feed

 
Vikram Virk
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
try{
myFile = newsForm.getTheFile();

String fileName = myFile.getFileName();

InputStream uploadInStream = myFile.getInputStream();

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

catch(FileNotFoundException fnfe){
}

Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!