users@glassfish.java.net

Re: JSF - referencing images outside of deployed .ear

From: <glassfish_at_javadesktop.org>
Date: Thu, 03 May 2007 07:43:56 PDT

Ahh, ok, that makes sense - I've done something similar to this using jfreechart in JSP.

Ugh...not what I was hoping to hear...but thanks for the info! I think I might just stick w/ Wicket. I can't get excited about JSF...I keep trying, however.

I've found, through trial-and-error, that the [ code ] [ / code ] blocks work here (remove spaces, obviously).

[code]
package com.horstmann.qq.web;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetImageServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
String id = request.getParameter("id");
String extension = id.substring(id.lastIndexOf('.') + 1);
response.setContentType("image/" + extension);
String imageDirectory = getServletContext().getInitParameter("com.horstmann.qq.imagePath");
FileInputStream in = new FileInputStream(new File(new File(imageDirectory), id));
OutputStream out = response.getOutputStream();
final int BUFFER_SIZE = 1024;
byte[] buffer = new byte[BUFFER_SIZE];
int n = 0;
while (-1 != (n = in.read(buffer))) {
out.write(buffer, 0, n);
}
in.close();
out.close();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
[/code]
[Message sent by forum member 'zambizzi' (zambizzi)]

http://forums.java.net/jive/thread.jspa?messageID=215356