I have something that works:
in web.xml:
<servlet>
<servlet-name>imageServlet</servlet-name>
<servlet-class>ImageServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>imageServlet</servlet-name>
<url-pattern>/users/image/*</url-pattern>
</servlet-mapping>
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
resp.setContentType("jpg");
// Set content size
File file = new File(fileName);
resp.setContentLength((int) file.length());
resp.setContentType("image/jpeg");
// 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: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]