Pictures publishing ver. 1.9

        Servlet allows you to quickly build a photo album. ImagesServlet displays all the graphical files (.gif , .jpg and .png files) from the given directory. You can use servlet's default view for files (a grid of images) or provide your own JSP file for the view. How to use it:

1) copy ImagesServlet.jar into WEB-INF/lib directory

2) describe Images servlet in your web.xml file:


3) describe a mapping for this servlet


You must provide a configuration file describes how to display pictures as well as various interface settings. You can use ImagesServlet in two forms:

a) pass configuration file as a parameter. E.g.:


b) define your configuration file as an initial parameter for servlet (parameter name is config):


and use servlet in this form:


Configuration file is a text file, each line describes one parameter in the form of


Empty lines and any line starts with # or // are ignored. Current version supports the following list of parameters:

# dir - base directory. This parameter is mandatory

# title. Describes a title for page. Default value is empty (no title)
title=My pictures

# header. You can set here some file contains any html-code.
# This code will be outputted at the beginning of the each page.
# So you can set for example some banners or CSS styles.
# By default this value is empty

# footer. You can set here some file contains any html-code. This code will be
# outputted at the bottom of the each page. So you can set for example some banners.
# By default this value is empty

# bgcolor. Background color. Default value is #FFFFFF (white)

# fgcolor. Foreground color. Default value is #000000 (black)

# face. Font face. By default is current browser's font

# size. Font size. By default is current browser's font

# col. Columns - how many pictures per row. Default value is 5

# space. Space between pictures. Default value is 20

# width. Width size for small pictures. Default value is 100

# height. Height size for small pictures. Default value is 50

# border. Border size for small pictures. Default value is 1

# rel. Optional parameter. Describes a rel attribute for links to images. By default is empty

# expires. This parameter describes a caching time (in seconds) for the images (client side cache).

# names. Show/do not show titles (file names) for pictures.
# Default value is 1 (show titles)

# order. Describes how to sort images. Possibly values are: 1 - order by name,
#2 - order by the date descendent. Default value is 1 (order by name)

# target. Parameter target describes a frame for showing
# pictures. By default this value is _blank - show in the new window.
# E.g. show in the same window:

# view. Parameter view describes a path to your JSP file
# for the processing. E.g.:

Customized view

Parameter view describes your own JSP file for rendering the images. Servlet will scan images directory provided in the config file and forward request to the JSP file for the future processing. The list of files will be available as a request's scope attribute imagefiles. Type for this attribute is java.util.ArrayList. Each element is a file bean (com.jsos.pubpic.FileBean) with the following methods:

String getName() file name
String getSize() file size
String getTime() modification date

E.g. code example for your JSP:

  java.util.ArrayList images = (java.util.ArrayList)request.getAttribute("imagefiles");
  java.util.Iterator it = images.iterator();
  while (it.hasNext())
   com.jsos.pubpic.FileBean image = (com.jsos.pubpic.FileBean);
Image file:"+image.getName());

or with JSTL:

<c:forEach items="${imagefiles}" var="image">
  <c:out value="${}"/><br/>

You can display image file via the same Images servlet. E.g.:

<img src="/servlet/Images?show=your_file_name">

Note: configuration file can be saved anywhere on your server. E.g. if you are using ImagesServlet?config line we assume this file is saved under the root directory (docBase) of your container. But you can of course always use full name for setting config file location: Images?/home/users/my_file (or Images?c:\users\my_file)

For JSP check out also Album taglib in Coldtags suite

Note: the evaluation version of servlet displays up to 10 files

For downloading:

servlet: ImagesServlet.jar
sample of config file:  confpic

 © Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: