I don't understand why you can not use a servlet ? I the example above I'm using a servlet that prints the photo. It takes as parameter an Id. I put it in the admin section because this feature is available only for admin, so in your case put it wherever you want.
On Tue, Aug 10, 2010 at 3:52 PM, Amit Goyal <goya...@gmail.com> wrote: > In Appfuse, we don't use servlets. I am using struts where Action classes > extends BaseAction class. Another question: why the pics are in "admin" > path? > > One solution that worked for me is that I saved the pics in a public folder > (accessible by direct url). Then the Action class sends the path of the pic > to jsp, and that path is saved in database. Next, jsp just points to that > url and the pic is shown. Clearly, it doesn't allow us to set privacy > settings to pics. Ad hoc method to fix this is to set the filename something > long and messy, so it is not easy to remember/guess. > > Cheers, > Amit > > > On Tue, Aug 10, 2010 at 6:28 AM, ramzi khlil <ramzi.atv...@gmail.com>wrote: > >> 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 >>> >>> >>> >> >