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
# title. Describes a title for page. Default value is empty (no title)
# header. You can set here some file contains any html-code.
# footer. You can set here some file contains any html-code. This code
will be
# 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.
# order. Describes how to sort images. Possibly values are: 1 - order by name,
# target. Parameter target describes a frame for showing
# view. Parameter view describes a path to your JSP file
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
See also JSOS - the largest collection of servlets and filters.
|
Also in JSOS:
|