tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrea Salvi" <tudhal...@gmail.com>
Subject Re: Commons fileUpload: write to disk permission problem
Date Tue, 27 Jun 2006 17:10:08 GMT
Hi again Tim :D
My servlet works fine now.... thanks a lot for your help!!!!!

Andrea

2006/6/26, Tim Lucia <timlucia@yahoo.com>:
>
> The servlet looks OK -- I didn't compile or run it or anything.  When you
> say a blank image -- are you requesting the servlet URL directly from the
> browser?  I'd snoop on the headers and see what comes back.  It sounds
> like
> it got a 404 or some other error.
>
> 1. Check http://your-host/path/.../servlet?ID=n with a browser -- check
> the
> headers (TamperData, etc. for FireFox)
> 2. Check the Tomcat logs for a 40x or 50x error
> 3. Check the path in the .jsp <img.../> tag and make sure it matches the
> path for #1.
>
> HTH,
> Tim
>
>
> > -----Original Message-----
> > From: Andrea Salvi [mailto:tudhalyas@gmail.com]
> > Sent: Monday, June 26, 2006 8:31 AM
> > To: Tomcat Users List
> > Subject: Re: Commons fileUpload: write to disk permission problem
> >
> > Hi Tim, and thanks for your answer. I did as you said and I made a
> servlet
> > that handles the users' avatars, but all I can get from the servlet is a
> > blank image. Here's the servlet code:
> >
> > ---------BEGIN OF FILE---------
> >
> > package servlet;
> >
> > import java.io.IOException;
> >
> > import javax.servlet.ServletException;
> > import javax.servlet.ServletOutputStream;
> > import javax.servlet.http.HttpServletRequest;
> > import javax.servlet.http.HttpServletResponse;
> > import javax.servlet.http.HttpSession;
> >
> > import data.UserInfoBean; // class that holds infos about the user,
> > including its avatar
> >
> > public class ShowAvatarServlet extends
> > javax.servlet.http.HttpServletimplements
> >         javax.servlet.Servlet {
> >
> >     public ShowAvatarServlet() {
> >         super();
> >     }
> >
> >     protected void doPost(HttpServletRequest request,
> >             HttpServletResponse response) throws ServletException,
> > IOException {
> >         HttpSession session = request.getSession();
> >         UserInfoBean userInfo = (UserInfoBean) session.getAttribute
> > ("userInfo");
> >
> >         String format = infoUtente.getAvatarType();
> >         //format can be image/jpeg, image/gif or image/x-png
> >
> >         byte[] image = infoUtente.getAvatar();
> >         response.setContentType(format);
> >         ServletOutputStream outputStream = response.getOutputStream();
> >         outputStream.write(image);
> >         outputStream.close();
> >     }
> >
> >     protected void doGet(HttpServletRequest request,
> >             HttpServletResponse response) throws ServletException,
> > IOException {
> >         this.doPost(request, response);
> >     }
> >
> > }
> >
> > -----END OF FILE-------
> >
> > Am I doing something wrong? Thanks for your help!
> >
> > Andrea
> >
> > 2006/6/26, Tim Lucia <timlucia@yahoo.com>:
> > >
> > > One way is to send back a reference to a servlet that knows how to
> > > retrieve
> > > the image.  I.e., in your .jsp, say:
> > >
> > > <img src="/path/to/avatar/servlet?avatar=1234"/>
> > >
> > > Where 1234 is the primary key (ID) field of the avatar in the
> DB.  Have
> > > the
> > > servlet set the response type to image/jpeg or image/png or whatever
> is
> > > appropriate, and then stream the bytes out of the blob from the DB.
> > >
> > > Tim
> > >
> > >
> > > > -----Original Message-----
> > > > From: Andrea Salvi [mailto:tudhalyas@gmail.com]
> > > > Sent: Monday, June 26, 2006 4:48 AM
> > > > To: Tomcat Users List
> > > > Subject: Re: Commons fileUpload: write to disk permission problem
> > > >
> > > > Hi David and thanks for the quick reply. I'll try to use the
> database
> > to
> > > > store the avatars but... I don't know how I can show those images in
> > my
> > > > JSP
> > > > pages :S Can you please tell me how to do that? Sorry for the noobie
> > > > question... :)
> > > >
> > > > Andrea
> > > >
> > > >
> > > >
> > > > 2006/6/26, David Delbecq <delbd@oma.be>:
> > > > >
> > > > > Do not write data in the webapplication folder, this folder is
> > > supposed
> > > > > to be overwritten when webapplication is redeployed and datas will
> > be
> > > > > lost. Instead choose a folder in system you dedicate to your
> > > > > webapplication datas and store your avatars there.
> > > > >
> > > > > Or best .... use a database :)
> > > > >
> > > > > Andrea Salvi wrote:
> > > > > > Hi there!
> > > > > > I'm making a forum application with JSP and Servlets, and I
> wanted
> > > to
> > > > > > give
> > > > > > to the final user the opportunity to upload an avatar to be
> > > displayed
> > > > > > into
> > > > > > his posts. I found the Commons fileUpload library and it works
> > quite
> > > > > > well,
> > > > > > except for a thing: I can't save the image on the server's file
> > > > system,
> > > > > > apparently due to a permission problem (as my program tries
to
> > write
> > > > > > in any
> > > > > > folder inside the web application context, Tomcat throws a
> > > > > > FileNotFoundException, saying that access to that folder is
> > denied).
> > > > > > Can you
> > > > > > tell me how can I fix this problem?
> > > > > >
> > > > > > Regards,
> > > > > > Andrea
> > > > > >
> > > > >
> > > > >
> > > > >
> --------------------------------------------------------------------
> > -
> > > > > To start a new topic, e-mail: users@tomcat.apache.org
> > > > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > > > For additional commands, e-mail: users-help@tomcat.apache.org
> > > > >
> > > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To start a new topic, e-mail: users@tomcat.apache.org
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message