OOP-ResearchMake It Simpler by Object Oriented Programming

How to set the maximum width/height of the image file by OOP MimeParser: Java API for file upload JSP/Servlet by multipart/form-data

Java API for file upload JSP/Servlet by multipart/form-data. It can set the maximum width/height of the image file (JPEG, GIF or PNG) to be uploaded. If the user tries to upload the larger files, your JSP/Servlet can catch the exception.
This page describes how to set the maximum width/height by OOP MimeParser.

Related Pages:


Width/height of the image file (JPEG, PNG or GIF) to be uploaded

To enable this feature, your JSP/Servlet container (such as Apache Tomcat, Jetty or WebLogic) must be run on JDK 1.4 or later.

If your web application accepts the multipart/form-data request for the image file (JPEG, PNG or GIF), you may want to set the maximum width/height of the image file to be uploaded. (As for the maximum file size, please read another page.) For example, you may build JSP/Servet for the online photo album, and you may want to set the maximum width/height of the JPEG to be uploaded.

With OOP MimeParser API, your JSP/Servlet can easily set the maximum width/height of the image file to be uploaded. If the user tries to upload the file with its larger width or height, OOP MimeParser API will throw the exception. Your JSP/Servlet can catch this exception and show the error message to the user.

All what you need is to place:

  • ImageSizeChecker.properties
into
  • (docBase)/WEB-INF/classes
of your web application context.
In addition, please edit:
  • (docBase)/WEB-INF/classes/MimeParser.properties
and specify the maximum width/height in it.

With this configuration, the following methods will check the width/height of the image file to be uploaded:
  • parseAndSave(HttpServletRequest req, String dir, Set mime)
  • parseAndSave(HttpServletRequest req, String ch, String dir, Set mime)
  • parseAndSave(HttpServletRequest req, String dir, int max, Set mime)
  • parseAndSave(HttpServletRequest req, String ch, String dir, int max, Set mime)
  • parseOnly(HttpServletRequest req, Set mime)
  • parseOnly(HttpServletRequest req, String ch, Set mime)
  • parseOnly(HttpServletRequest req, int max, Set mime)
  • parseOnly(HttpServletRequest req, String ch, int max, Set mime)
If the width or height of the uploaded image file is larger than the specified one, these methods will throw:
  • com.oopreserch.util.LargeImageException
From this exception, your JSP/Servlet can get:
  • The width of the uploaded image file
  • The height of the uploaded image file
  • The maximum width to be allowed
  • The maximum height to be allowed
  • The file name
So, you can show the helpful message to your user.

Caution!
All the APIs for Servlet/JSP introduced by this web site are now included in Bento framework:
  • Simpler than JSTL or Apache Struts
  • MVC framework by HTML
  • Input validation from CGI FORM
  • Easy user authentication
  • Easy localization (L10n)
To download the APIs and source code examples, please visit the web site of Bento framework.


JBuilder 2007


General Information

For Java Development

Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.


ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved.