tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Pedersen" <>
Subject Re: where to store user-generated files?
Date Wed, 21 Feb 2007 16:48:44 GMT
I have something that works:

in web.xml:



Links to user images are like this:

<img src="/starfriend/users/image/${match.thumbName}">

( I am using Velocity )

and this is the servlet:

public class ImageServlet extends HttpServlet {

	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
                String path = PhotoHandler.getUserImageDirectory();		
		String pathInfo = req.getPathInfo();
		String fileName = path + pathInfo;
                // Set content type

		// Set content size
		File file = new File(fileName);
		resp.setContentLength((int) file.length());

		// Open the file and output streams
		FileInputStream in = new FileInputStream(file);
		OutputStream out = resp.getOutputStream();

		// Copy the contents of the file to the output stream
		FileCopyUtils.copy(in, out);


Image directory path is held in a properties file, which is held in
memory by a class called PhotoHandler - that is just the way I have it
- of course the path to the image folder could be an init parameter of
the servlet.

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message