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:
 


    <servlet>
     <servlet-name>Images</servlet-name>
     <servlet-class>com.jsos.pubpic.ImagesServlet</servlet-class>
    </servlet>

3) describe a mapping for this servlet
 


    <servlet-mapping>
     <servlet-name>Images</servlet-name>
     <url-pattern>/servlet/Images</url-pattern>
     </servlet-mapping>

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.:
 


http://your_host/servlet/Images?config_file

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


    <servlet>
     <servlet-name>Images</servlet-name>
     <servlet-class>com.jsos.pubpic.ImagesServlet</servlet-class>
     <init-param>
      <param-name>config</param-name>
      <param-value>path_to_your_configuration_file</param-value>
     </init-param>
    </servlet>

and use servlet in this form:
 


http://your_host/servlet/Images

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

    parameter=value

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
dir=your_directory_with_graph_files

# 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
header=path_to_your_file

# 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
footer=path_to_your_file

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

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

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

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

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

# space. Space between pictures. Default value is 20
space=20

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

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

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

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

# 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)
names=0

# 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)
order=1

# 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:
target=_self

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

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)it.next();
   out.orintln("
Image file:"+image.getName());
  }
%>

or with JSTL:
 


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

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: