You can use a servlet that print the photo on your page.

Here is the needed code:
<li class="info">
         <Admin:label styleClass="desc" key="user.photo"/>
         <img src="<c:url value="/admin/userPhoto?id=${user.id}"/>"
height="150" width="150"/>
     </li>

For the servlet:

try {
             userId = Long.parseLong(_userId);
             UserPhoto userPhoto =
userPhotoManager.getUserPhotoByUserId(userId);
          _userPhoto = userPhoto.getPhoto();
             // flush it in the response
             httpServletResponse.setHeader("Cache-Control", "no-store");
             httpServletResponse.setHeader("Pragma", "no-cache");
             httpServletResponse.setDateHeader("Expires", 0);
             httpServletResponse.setContentType("image/jpeg");
             ServletOutputStream responseOutputStream =
                     httpServletResponse.getOutputStream();
             responseOutputStream.write(_userPhoto);
             responseOutputStream.flush();
             responseOutputStream.close();
            } catch (NumberFormatException nfe) {

            }
So your userPhotoManager can fetch the photo either from a database or from
a filesystem.

Hope this helps !
Ramzi

On Mon, Aug 9, 2010 at 8:37 PM, Amit Goyal <goya...@gmail.com> wrote:

> Hi,
>
> I am using Appfuse for my application. Its a great starting point and
> thanks to all the developers. In my application, I want to add "profile
> picture" functionality. I looked over internet and I am kind of confused
> what is the best way to do it. It would be great if someone can help me
> here.
>
> Here is what I found. There are two ways to store and serve images:
>
> 1. Store images in a database. Lot of links suggest that it is not the best
> way especially if the images are large (and many), which I think is a valid
> point. JFYI, I am using MySQL.
>
> 2. Store images in filesystem. Looks like this solution is not a clean
> solution and it might be difficult to migrate the application (in future if
> needed). And it is slower than the database operation. But it is still good.
>
> My first question is: which is better and scalable? Is there a good
> article/discussion about it?
>
> My second question is related to serving the image to jsp: even after
> looking at so many forums, its still not clear to me how to store and serve
> images in the appfuse settings (in any of the two options). Imagine an
> action servlet (lets call it UserAction) which serves some attributes (like
> user name, age, gender etc). To serve the image to jsp, can I just add new
> private variable like
>
> private byte[] image;
>
> and build the image when the servlet is called OR do I need another
> servlet?
>
> Finally, for now I am assuming that code to store images would be similar
> to one in FileUploadAction.java (if it is stored in filesystem). Am I right?
>
> Thanks a lot,
> Amit
>
>
>

Reply via email to