You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by CD <dc...@gmail.com> on 2006/06/12 22:47:07 UTC

Re: Sending a file to ServletContext Response failure

Johnny,

Try setting the header for the response:

response.setHeader("Content-disposition", "attachment; filename="+filename);

Regards,
CD


On 6/12/06, Johnny Gonzalez <jo...@yahoo.es> wrote:
>
> Hello everybody,
>
> I have to send a file to the response for the browser
> to show a save/open file dialog box to the user, so
> he/she can download it and save in in his/her local
> file system. As expected the file is stored in a
> specific directory in the file system of the server.
>
> What I did was to call this method within a
> commandLink component:
>
> public String downloadDB(){
>      FacesContext context =
> FacesContext.getCurrentInstance();
>
>      HttpServletRequest request = (
> HttpServletRequest )
>
> context.getExternalContext().getRequest(  );
>      HttpServletResponse response =
>         ( HttpServletResponse )
> context.getExternalContext().getResponse();
>
>      String filePath = null;
>      int read = 0;
>      byte[] bytes = new byte[1024];
>
>      filePath = getMyDBPath();
>
>      response.setContentType("application/pdf");
>      FileInputStream fis = null;
>      OutputStream os = null;
>
>      try {
>         fis = new FileInputStream(new
> File(filePath));
>         os = response.getOutputStream();
>         while((read = fis.read(bytes)) != -1){
>            os.write(bytes,0,read);
>         }
>         os.flush();
>         os.close();
>      }
>      catch ( FileNotFoundException e1 ) {
>         logger.error(e1);
>         logger.info(e1.getMessage());
>         request.setAttribute("errors", "File Not
> Found.");
>      }
>      catch ( IOException ioe ) {
>         logger.error(ioe);
>         logger.info(ioe.getMessage());
>         request.setAttribute("errors", "Error reading
> file.");
>      }
>      return "";
>   }
>
>
>
> After the user clicks on the commandLink, the page I'm
> working on, gets refreshed and at the top of it
> appears the text of the file I tried to download. This
> is not the expected behaviour, what should I do?
>
> thanks a lot,
> Johnny
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam
> ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>

Re: Sending a file to ServletContext Response failure

Posted by Matthias Wessendorf <ma...@apache.org>.
renamed (and linked to FrontPage)

http://wiki.apache.org/myfaces/Sending_Files

On 6/12/06, Matthias Wessendorf <ma...@apache.org> wrote:
> I saw the entry
>
> thanks!
>
> http://tinyurl.com/oae4a
>
> On 6/12/06, Johnny Gonzalez <jo...@yahoo.es> wrote:
> > Hello Matthias,
> >
> > I submitted the change to the wiki, but it still
> > doesn't appear, does it have to pass an authorisation
> > phase before appearing in the wiki??
> >
> > Thanks a lot,
> >
> > Johnny
> >  --- Matthias Wessendorf <ma...@apache.org> escribió:
> >
> > > easy to create a password (use the login link)
> > >
> > > added to
> > >
> > > "JSF and MyFaces in Praxis: Specialized Trails"
> > >
> > > and create a subtitle like "sending files (like PDF)
> > > to the browser"
> > >
> > > something like that.
> > >
> > >
> > >
> > > On 6/12/06, Johnny Gonzalez
> > > <jo...@yahoo.es> wrote:
> > > > Hello Matthias,
> > > >
> > > > I'd like to, but I have no idea where to put it on
> > > the
> > > > wiki, Where do you recommend me to post it?
> > > >
> > > > Do I need a password for doing so?
> > > >
> > > > Thanks a lot,
> > > > Johnny
> > > >  --- Matthias Wessendorf <ma...@apache.org>
> > > escribió:
> > > >
> > > > > Johnny,
> > > > >
> > > > > this has been asked a lot. So since you got a
> > > nice
> > > > > hint,
> > > > > can you bring it to our wiki page ([1]).
> > > > >
> > > > > Would be great!
> > > > >
> > > > > Thx,
> > > > > Matthias
> > > > >
> > > > > [1] http://wiki.apache.org/myfaces
> > > > >
> > > > > On 6/12/06, Johnny Gonzalez
> > > > > <jo...@yahoo.es> wrote:
> > > > > > Hello CD,
> > > > > >
> > > > > > Thanks a lot, that worked perfect :-D
> > > > > >
> > > > > > Johnny
> > > > > >  --- CD <dc...@gmail.com> escribió:
> > > > > >
> > > > > > > Johnny,
> > > > > > >
> > > > > > > Try setting the header for the response:
> > > > > > >
> > > > > > > response.setHeader("Content-disposition",
> > > > > > > "attachment; filename="+filename);
> > > > > > >
> > > > > > > Regards,
> > > > > > > CD
> > > > > > >
> > > > > > >
> > > > > > > On 6/12/06, Johnny Gonzalez
> > > > > > > <jo...@yahoo.es> wrote:
> > > > > > > >
> > > > > > > > Hello everybody,
> > > > > > > >
> > > > > > > > I have to send a file to the response for
> > > the
> > > > > > > browser
> > > > > > > > to show a save/open file dialog box to the
> > > > > user,
> > > > > > > so
> > > > > > > > he/she can download it and save in in
> > > his/her
> > > > > > > local
> > > > > > > > file system. As expected the file is
> > > stored in
> > > > > a
> > > > > > > > specific directory in the file system of
> > > the
> > > > > > > server.
> > > > > > > >
> > > > > > > > What I did was to call this method within
> > > a
> > > > > > > > commandLink component:
> > > > > > > >
> > > > > > > > public String downloadDB(){
> > > > > > > >      FacesContext context =
> > > > > > > > FacesContext.getCurrentInstance();
> > > > > > > >
> > > > > > > >      HttpServletRequest request = (
> > > > > > > > HttpServletRequest )
> > > > > > > >
> > > > > > > > context.getExternalContext().getRequest(
> > > );
> > > > > > > >      HttpServletResponse response =
> > > > > > > >         ( HttpServletResponse )
> > > > > > > >
> > > context.getExternalContext().getResponse();
> > > > > > > >
> > > > > > > >      String filePath = null;
> > > > > > > >      int read = 0;
> > > > > > > >      byte[] bytes = new byte[1024];
> > > > > > > >
> > > > > > > >      filePath = getMyDBPath();
> > > > > > > >
> > > > > > > >
> > > > > response.setContentType("application/pdf");
> > > > > > > >      FileInputStream fis = null;
> > > > > > > >      OutputStream os = null;
> > > > > > > >
> > > > > > > >      try {
> > > > > > > >         fis = new FileInputStream(new
> > > > > > > > File(filePath));
> > > > > > > >         os = response.getOutputStream();
> > > > > > > >         while((read = fis.read(bytes)) !=
> > > -1){
> > > > > > > >            os.write(bytes,0,read);
> > > > > > > >         }
> > > > > > > >         os.flush();
> > > > > > > >         os.close();
> > > > > > > >      }
> > > > > > > >      catch ( FileNotFoundException e1 ) {
> > > > > > > >         logger.error(e1);
> > > > > > > >         logger.info(e1.getMessage());
> > > > > > > >         request.setAttribute("errors",
> > > "File
> > > > > Not
> > > > > > > > Found.");
> > > > > > > >      }
> > > > > > > >      catch ( IOException ioe ) {
> > > > > > > >         logger.error(ioe);
> > > > > > > >         logger.info(ioe.getMessage());
> > > > > > > >         request.setAttribute("errors",
> > > "Error
> > > > > > > reading
> > > > > > > > file.");
> > > > > > > >      }
> > > > > > > >      return "";
> > > > > > > >   }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > After the user clicks on the commandLink,
> > > the
> > > > > page
> > > > > > > I'm
> > > > > > > > working on, gets refreshed and at the top
> > > of
> > > > > it
> > > > > > > > appears the text of the file I tried to
> > > > > download.
> > > > > > > This
> > > > > > > > is not the expected behaviour, what should
> > > I
> > > > > do?
> > > > > > > >
> > > > > > > > thanks a lot,
> > > > > > > > Johnny
> > > > > > > >
> > > > > > > >
> > > > >
> > > __________________________________________________
> > > > > > > > Correo Yahoo!
> > > > > > > > Espacio para todos tus mensajes, antivirus
> > > y
> > > > > > > antispam
> > > > > > > > ¡gratis!
> > > > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > > > >
> > > > > > > >
> > > > >
> > > __________________________________________________
> > > > > > > > Correo Yahoo!
> > > > > > > > Espacio para todos tus mensajes, antivirus
> > > y
> > > > > > > antispam ¡gratis!
> > > > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > __________________________________________________
> > > > > > Correo Yahoo!
> > > > > > Espacio para todos tus mensajes, antivirus y
> > > > > antispam
> > > > > > ¡gratis!
> > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > >
> > > > > >
> > > __________________________________________________
> > > > > > Correo Yahoo!
> > > > > > Espacio para todos tus mensajes, antivirus y
> > > > > antispam ¡gratis!
> > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > >
> > > > >
> > > > >
> > > > > --
> > >
> > === message truncated ===
> >
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y antispam
> > ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
>
>
> --
> Matthias Wessendorf
> Aechterhoek 18
> 48282 Emsdetten
> blog: http://jroller.com/page/mwessendorf
> mail: mwessendorf-at-gmail-dot-com
>


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: Sending a file to ServletContext Response failure

Posted by Johnny Gonzalez <jo...@yahoo.es>.
Thanks to you for the opportunity to colaborate :-)

with the help of: CD

 --- Matthias Wessendorf <ma...@apache.org> escribió:

> I saw the entry
> 
> thanks!
> 
> http://tinyurl.com/oae4a
> 
> On 6/12/06, Johnny Gonzalez
> <jo...@yahoo.es> wrote:
> > Hello Matthias,
> >
> > I submitted the change to the wiki, but it still
> > doesn't appear, does it have to pass an
> authorisation
> > phase before appearing in the wiki??
> >
> > Thanks a lot,
> >
> > Johnny
> >  --- Matthias Wessendorf <ma...@apache.org>
> escribió:
> >
> > > easy to create a password (use the login link)
> > >
> > > added to
> > >
> > > "JSF and MyFaces in Praxis: Specialized Trails"
> > >
> > > and create a subtitle like "sending files (like
> PDF)
> > > to the browser"
> > >
> > > something like that.
> > >
> > >
> > >
> > > On 6/12/06, Johnny Gonzalez
> > > <jo...@yahoo.es> wrote:
> > > > Hello Matthias,
> > > >
> > > > I'd like to, but I have no idea where to put
> it on
> > > the
> > > > wiki, Where do you recommend me to post it?
> > > >
> > > > Do I need a password for doing so?
> > > >
> > > > Thanks a lot,
> > > > Johnny
> > > >  --- Matthias Wessendorf <ma...@apache.org>
> > > escribió:
> > > >
> > > > > Johnny,
> > > > >
> > > > > this has been asked a lot. So since you got
> a
> > > nice
> > > > > hint,
> > > > > can you bring it to our wiki page ([1]).
> > > > >
> > > > > Would be great!
> > > > >
> > > > > Thx,
> > > > > Matthias
> > > > >
> > > > > [1] http://wiki.apache.org/myfaces
> > > > >
> > > > > On 6/12/06, Johnny Gonzalez
> > > > > <jo...@yahoo.es> wrote:
> > > > > > Hello CD,
> > > > > >
> > > > > > Thanks a lot, that worked perfect :-D
> > > > > >
> > > > > > Johnny
> > > > > >  --- CD <dc...@gmail.com> escribió:
> > > > > >
> > > > > > > Johnny,
> > > > > > >
> > > > > > > Try setting the header for the response:
> > > > > > >
> > > > > > >
> response.setHeader("Content-disposition",
> > > > > > > "attachment; filename="+filename);
> > > > > > >
> > > > > > > Regards,
> > > > > > > CD
> > > > > > >
> > > > > > >
> > > > > > > On 6/12/06, Johnny Gonzalez
> > > > > > > <jo...@yahoo.es> wrote:
> > > > > > > >
> > > > > > > > Hello everybody,
> > > > > > > >
> > > > > > > > I have to send a file to the response
> for
> > > the
> > > > > > > browser
> > > > > > > > to show a save/open file dialog box to
> the
> > > > > user,
> > > > > > > so
> > > > > > > > he/she can download it and save in in
> > > his/her
> > > > > > > local
> > > > > > > > file system. As expected the file is
> > > stored in
> > > > > a
> > > > > > > > specific directory in the file system
> of
> > > the
> > > > > > > server.
> > > > > > > >
> > > > > > > > What I did was to call this method
> within
> > > a
> > > > > > > > commandLink component:
> > > > > > > >
> > > > > > > > public String downloadDB(){
> > > > > > > >      FacesContext context =
> > > > > > > > FacesContext.getCurrentInstance();
> > > > > > > >
> > > > > > > >      HttpServletRequest request = (
> > > > > > > > HttpServletRequest )
> > > > > > > >
> > > > > > > >
> context.getExternalContext().getRequest(
> > > );
> > > > > > > >      HttpServletResponse response =
> > > > > > > >         ( HttpServletResponse )
> > > > > > > >
> > > context.getExternalContext().getResponse();
> > > > > > > >
> > > > > > > >      String filePath = null;
> > > > > > > >      int read = 0;
> > > > > > > >      byte[] bytes = new byte[1024];
> > > > > > > >
> > > > > > > >      filePath = getMyDBPath();
> > > > > > > >
> > > > > > > >
> > > > > response.setContentType("application/pdf");
> > > > > > > >      FileInputStream fis = null;
> > > > > > > >      OutputStream os = null;
> > > > > > > >
> > > > > > > >      try {
> > > > > > > >         fis = new FileInputStream(new
> > > > > > > > File(filePath));
> > > > > > > >         os =
> response.getOutputStream();
> > > > > > > >         while((read = fis.read(bytes))
> !=
> > > -1){
> > > > > > > >            os.write(bytes,0,read);
> > > > > > > >         }
> > > > > > > >         os.flush();
> > > > > > > >         os.close();
> > > > > > > >      }
> > > > > > > >      catch ( FileNotFoundException e1
> ) {
> > > > > > > >         logger.error(e1);
> > > > > > > >         logger.info(e1.getMessage());
> > > > > > > >         request.setAttribute("errors",
> > > "File
> > > > > Not
> > > > > > > > Found.");
> > > > > > > >      }
> > > > > > > >      catch ( IOException ioe ) {
> > > > > > > >         logger.error(ioe);
> > > > > > > >         logger.info(ioe.getMessage());
> > > > > > > >         request.setAttribute("errors",
> > > "Error
> > > > > > > reading
> > > > > > > > file.");
> > > > > > > >      }
> > > > > > > >      return "";
> > > > > > > >   }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > After the user clicks on the
> commandLink,
> > > the
> > > > > page
> > > > > > > I'm
> > > > > > > > working on, gets refreshed and at the
> top
> > > of
> > > > > it
> > > > > > > > appears the text of the file I tried
> to
> > > > > download.
> > > > > > > This
> > > > > > > > is not the expected behaviour, what
> should
> > > I
> > > > > do?
> > > > > > > >
> > > > > > > > thanks a lot,
> > > > > > > > Johnny
> > > > > > > >
> > > > > > > >
> > > > >
> > >
> __________________________________________________
> 
=== message truncated ===


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam
¡gratis! 
Regístrate ya - http://correo.yahoo.es 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.es 

Re: Sending a file to ServletContext Response failure

Posted by Matthias Wessendorf <ma...@apache.org>.
I saw the entry

thanks!

http://tinyurl.com/oae4a

On 6/12/06, Johnny Gonzalez <jo...@yahoo.es> wrote:
> Hello Matthias,
>
> I submitted the change to the wiki, but it still
> doesn't appear, does it have to pass an authorisation
> phase before appearing in the wiki??
>
> Thanks a lot,
>
> Johnny
>  --- Matthias Wessendorf <ma...@apache.org> escribió:
>
> > easy to create a password (use the login link)
> >
> > added to
> >
> > "JSF and MyFaces in Praxis: Specialized Trails"
> >
> > and create a subtitle like "sending files (like PDF)
> > to the browser"
> >
> > something like that.
> >
> >
> >
> > On 6/12/06, Johnny Gonzalez
> > <jo...@yahoo.es> wrote:
> > > Hello Matthias,
> > >
> > > I'd like to, but I have no idea where to put it on
> > the
> > > wiki, Where do you recommend me to post it?
> > >
> > > Do I need a password for doing so?
> > >
> > > Thanks a lot,
> > > Johnny
> > >  --- Matthias Wessendorf <ma...@apache.org>
> > escribió:
> > >
> > > > Johnny,
> > > >
> > > > this has been asked a lot. So since you got a
> > nice
> > > > hint,
> > > > can you bring it to our wiki page ([1]).
> > > >
> > > > Would be great!
> > > >
> > > > Thx,
> > > > Matthias
> > > >
> > > > [1] http://wiki.apache.org/myfaces
> > > >
> > > > On 6/12/06, Johnny Gonzalez
> > > > <jo...@yahoo.es> wrote:
> > > > > Hello CD,
> > > > >
> > > > > Thanks a lot, that worked perfect :-D
> > > > >
> > > > > Johnny
> > > > >  --- CD <dc...@gmail.com> escribió:
> > > > >
> > > > > > Johnny,
> > > > > >
> > > > > > Try setting the header for the response:
> > > > > >
> > > > > > response.setHeader("Content-disposition",
> > > > > > "attachment; filename="+filename);
> > > > > >
> > > > > > Regards,
> > > > > > CD
> > > > > >
> > > > > >
> > > > > > On 6/12/06, Johnny Gonzalez
> > > > > > <jo...@yahoo.es> wrote:
> > > > > > >
> > > > > > > Hello everybody,
> > > > > > >
> > > > > > > I have to send a file to the response for
> > the
> > > > > > browser
> > > > > > > to show a save/open file dialog box to the
> > > > user,
> > > > > > so
> > > > > > > he/she can download it and save in in
> > his/her
> > > > > > local
> > > > > > > file system. As expected the file is
> > stored in
> > > > a
> > > > > > > specific directory in the file system of
> > the
> > > > > > server.
> > > > > > >
> > > > > > > What I did was to call this method within
> > a
> > > > > > > commandLink component:
> > > > > > >
> > > > > > > public String downloadDB(){
> > > > > > >      FacesContext context =
> > > > > > > FacesContext.getCurrentInstance();
> > > > > > >
> > > > > > >      HttpServletRequest request = (
> > > > > > > HttpServletRequest )
> > > > > > >
> > > > > > > context.getExternalContext().getRequest(
> > );
> > > > > > >      HttpServletResponse response =
> > > > > > >         ( HttpServletResponse )
> > > > > > >
> > context.getExternalContext().getResponse();
> > > > > > >
> > > > > > >      String filePath = null;
> > > > > > >      int read = 0;
> > > > > > >      byte[] bytes = new byte[1024];
> > > > > > >
> > > > > > >      filePath = getMyDBPath();
> > > > > > >
> > > > > > >
> > > > response.setContentType("application/pdf");
> > > > > > >      FileInputStream fis = null;
> > > > > > >      OutputStream os = null;
> > > > > > >
> > > > > > >      try {
> > > > > > >         fis = new FileInputStream(new
> > > > > > > File(filePath));
> > > > > > >         os = response.getOutputStream();
> > > > > > >         while((read = fis.read(bytes)) !=
> > -1){
> > > > > > >            os.write(bytes,0,read);
> > > > > > >         }
> > > > > > >         os.flush();
> > > > > > >         os.close();
> > > > > > >      }
> > > > > > >      catch ( FileNotFoundException e1 ) {
> > > > > > >         logger.error(e1);
> > > > > > >         logger.info(e1.getMessage());
> > > > > > >         request.setAttribute("errors",
> > "File
> > > > Not
> > > > > > > Found.");
> > > > > > >      }
> > > > > > >      catch ( IOException ioe ) {
> > > > > > >         logger.error(ioe);
> > > > > > >         logger.info(ioe.getMessage());
> > > > > > >         request.setAttribute("errors",
> > "Error
> > > > > > reading
> > > > > > > file.");
> > > > > > >      }
> > > > > > >      return "";
> > > > > > >   }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > After the user clicks on the commandLink,
> > the
> > > > page
> > > > > > I'm
> > > > > > > working on, gets refreshed and at the top
> > of
> > > > it
> > > > > > > appears the text of the file I tried to
> > > > download.
> > > > > > This
> > > > > > > is not the expected behaviour, what should
> > I
> > > > do?
> > > > > > >
> > > > > > > thanks a lot,
> > > > > > > Johnny
> > > > > > >
> > > > > > >
> > > >
> > __________________________________________________
> > > > > > > Correo Yahoo!
> > > > > > > Espacio para todos tus mensajes, antivirus
> > y
> > > > > > antispam
> > > > > > > ¡gratis!
> > > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > > >
> > > > > > >
> > > >
> > __________________________________________________
> > > > > > > Correo Yahoo!
> > > > > > > Espacio para todos tus mensajes, antivirus
> > y
> > > > > > antispam ¡gratis!
> > > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > __________________________________________________
> > > > > Correo Yahoo!
> > > > > Espacio para todos tus mensajes, antivirus y
> > > > antispam
> > > > > ¡gratis!
> > > > > Regístrate ya - http://correo.yahoo.es
> > > > >
> > > > >
> > __________________________________________________
> > > > > Correo Yahoo!
> > > > > Espacio para todos tus mensajes, antivirus y
> > > > antispam ¡gratis!
> > > > > Regístrate ya - http://correo.yahoo.es
> > > > >
> > > >
> > > >
> > > > --
> >
> === message truncated ===
>
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam
> ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: Sending a file to ServletContext Response failure

Posted by Johnny Gonzalez <jo...@yahoo.es>.
Hello Matthias,

I submitted the change to the wiki, but it still
doesn't appear, does it have to pass an authorisation
phase before appearing in the wiki??

Thanks a lot,

Johnny
 --- Matthias Wessendorf <ma...@apache.org> escribió:

> easy to create a password (use the login link)
> 
> added to
> 
> "JSF and MyFaces in Praxis: Specialized Trails"
> 
> and create a subtitle like "sending files (like PDF)
> to the browser"
> 
> something like that.
> 
> 
> 
> On 6/12/06, Johnny Gonzalez
> <jo...@yahoo.es> wrote:
> > Hello Matthias,
> >
> > I'd like to, but I have no idea where to put it on
> the
> > wiki, Where do you recommend me to post it?
> >
> > Do I need a password for doing so?
> >
> > Thanks a lot,
> > Johnny
> >  --- Matthias Wessendorf <ma...@apache.org>
> escribió:
> >
> > > Johnny,
> > >
> > > this has been asked a lot. So since you got a
> nice
> > > hint,
> > > can you bring it to our wiki page ([1]).
> > >
> > > Would be great!
> > >
> > > Thx,
> > > Matthias
> > >
> > > [1] http://wiki.apache.org/myfaces
> > >
> > > On 6/12/06, Johnny Gonzalez
> > > <jo...@yahoo.es> wrote:
> > > > Hello CD,
> > > >
> > > > Thanks a lot, that worked perfect :-D
> > > >
> > > > Johnny
> > > >  --- CD <dc...@gmail.com> escribió:
> > > >
> > > > > Johnny,
> > > > >
> > > > > Try setting the header for the response:
> > > > >
> > > > > response.setHeader("Content-disposition",
> > > > > "attachment; filename="+filename);
> > > > >
> > > > > Regards,
> > > > > CD
> > > > >
> > > > >
> > > > > On 6/12/06, Johnny Gonzalez
> > > > > <jo...@yahoo.es> wrote:
> > > > > >
> > > > > > Hello everybody,
> > > > > >
> > > > > > I have to send a file to the response for
> the
> > > > > browser
> > > > > > to show a save/open file dialog box to the
> > > user,
> > > > > so
> > > > > > he/she can download it and save in in
> his/her
> > > > > local
> > > > > > file system. As expected the file is
> stored in
> > > a
> > > > > > specific directory in the file system of
> the
> > > > > server.
> > > > > >
> > > > > > What I did was to call this method within
> a
> > > > > > commandLink component:
> > > > > >
> > > > > > public String downloadDB(){
> > > > > >      FacesContext context =
> > > > > > FacesContext.getCurrentInstance();
> > > > > >
> > > > > >      HttpServletRequest request = (
> > > > > > HttpServletRequest )
> > > > > >
> > > > > > context.getExternalContext().getRequest( 
> );
> > > > > >      HttpServletResponse response =
> > > > > >         ( HttpServletResponse )
> > > > > >
> context.getExternalContext().getResponse();
> > > > > >
> > > > > >      String filePath = null;
> > > > > >      int read = 0;
> > > > > >      byte[] bytes = new byte[1024];
> > > > > >
> > > > > >      filePath = getMyDBPath();
> > > > > >
> > > > > >
> > > response.setContentType("application/pdf");
> > > > > >      FileInputStream fis = null;
> > > > > >      OutputStream os = null;
> > > > > >
> > > > > >      try {
> > > > > >         fis = new FileInputStream(new
> > > > > > File(filePath));
> > > > > >         os = response.getOutputStream();
> > > > > >         while((read = fis.read(bytes)) !=
> -1){
> > > > > >            os.write(bytes,0,read);
> > > > > >         }
> > > > > >         os.flush();
> > > > > >         os.close();
> > > > > >      }
> > > > > >      catch ( FileNotFoundException e1 ) {
> > > > > >         logger.error(e1);
> > > > > >         logger.info(e1.getMessage());
> > > > > >         request.setAttribute("errors",
> "File
> > > Not
> > > > > > Found.");
> > > > > >      }
> > > > > >      catch ( IOException ioe ) {
> > > > > >         logger.error(ioe);
> > > > > >         logger.info(ioe.getMessage());
> > > > > >         request.setAttribute("errors",
> "Error
> > > > > reading
> > > > > > file.");
> > > > > >      }
> > > > > >      return "";
> > > > > >   }
> > > > > >
> > > > > >
> > > > > >
> > > > > > After the user clicks on the commandLink,
> the
> > > page
> > > > > I'm
> > > > > > working on, gets refreshed and at the top
> of
> > > it
> > > > > > appears the text of the file I tried to
> > > download.
> > > > > This
> > > > > > is not the expected behaviour, what should
> I
> > > do?
> > > > > >
> > > > > > thanks a lot,
> > > > > > Johnny
> > > > > >
> > > > > >
> > >
> __________________________________________________
> > > > > > Correo Yahoo!
> > > > > > Espacio para todos tus mensajes, antivirus
> y
> > > > > antispam
> > > > > > ¡gratis!
> > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > >
> > > > > >
> > >
> __________________________________________________
> > > > > > Correo Yahoo!
> > > > > > Espacio para todos tus mensajes, antivirus
> y
> > > > > antispam ¡gratis!
> > > > > > Regístrate ya - http://correo.yahoo.es
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> __________________________________________________
> > > > Correo Yahoo!
> > > > Espacio para todos tus mensajes, antivirus y
> > > antispam
> > > > ¡gratis!
> > > > Regístrate ya - http://correo.yahoo.es
> > > >
> > > >
> __________________________________________________
> > > > Correo Yahoo!
> > > > Espacio para todos tus mensajes, antivirus y
> > > antispam ¡gratis!
> > > > Regístrate ya - http://correo.yahoo.es
> > > >
> > >
> > >
> > > --
> 
=== message truncated ===


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam
¡gratis! 
Regístrate ya - http://correo.yahoo.es 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.es 

Re: Sending a file to ServletContext Response failure

Posted by Matthias Wessendorf <ma...@apache.org>.
easy to create a password (use the login link)

added to

"JSF and MyFaces in Praxis: Specialized Trails"

and create a subtitle like "sending files (like PDF) to the browser"

something like that.



On 6/12/06, Johnny Gonzalez <jo...@yahoo.es> wrote:
> Hello Matthias,
>
> I'd like to, but I have no idea where to put it on the
> wiki, Where do you recommend me to post it?
>
> Do I need a password for doing so?
>
> Thanks a lot,
> Johnny
>  --- Matthias Wessendorf <ma...@apache.org> escribió:
>
> > Johnny,
> >
> > this has been asked a lot. So since you got a nice
> > hint,
> > can you bring it to our wiki page ([1]).
> >
> > Would be great!
> >
> > Thx,
> > Matthias
> >
> > [1] http://wiki.apache.org/myfaces
> >
> > On 6/12/06, Johnny Gonzalez
> > <jo...@yahoo.es> wrote:
> > > Hello CD,
> > >
> > > Thanks a lot, that worked perfect :-D
> > >
> > > Johnny
> > >  --- CD <dc...@gmail.com> escribió:
> > >
> > > > Johnny,
> > > >
> > > > Try setting the header for the response:
> > > >
> > > > response.setHeader("Content-disposition",
> > > > "attachment; filename="+filename);
> > > >
> > > > Regards,
> > > > CD
> > > >
> > > >
> > > > On 6/12/06, Johnny Gonzalez
> > > > <jo...@yahoo.es> wrote:
> > > > >
> > > > > Hello everybody,
> > > > >
> > > > > I have to send a file to the response for the
> > > > browser
> > > > > to show a save/open file dialog box to the
> > user,
> > > > so
> > > > > he/she can download it and save in in his/her
> > > > local
> > > > > file system. As expected the file is stored in
> > a
> > > > > specific directory in the file system of the
> > > > server.
> > > > >
> > > > > What I did was to call this method within a
> > > > > commandLink component:
> > > > >
> > > > > public String downloadDB(){
> > > > >      FacesContext context =
> > > > > FacesContext.getCurrentInstance();
> > > > >
> > > > >      HttpServletRequest request = (
> > > > > HttpServletRequest )
> > > > >
> > > > > context.getExternalContext().getRequest(  );
> > > > >      HttpServletResponse response =
> > > > >         ( HttpServletResponse )
> > > > > context.getExternalContext().getResponse();
> > > > >
> > > > >      String filePath = null;
> > > > >      int read = 0;
> > > > >      byte[] bytes = new byte[1024];
> > > > >
> > > > >      filePath = getMyDBPath();
> > > > >
> > > > >
> > response.setContentType("application/pdf");
> > > > >      FileInputStream fis = null;
> > > > >      OutputStream os = null;
> > > > >
> > > > >      try {
> > > > >         fis = new FileInputStream(new
> > > > > File(filePath));
> > > > >         os = response.getOutputStream();
> > > > >         while((read = fis.read(bytes)) != -1){
> > > > >            os.write(bytes,0,read);
> > > > >         }
> > > > >         os.flush();
> > > > >         os.close();
> > > > >      }
> > > > >      catch ( FileNotFoundException e1 ) {
> > > > >         logger.error(e1);
> > > > >         logger.info(e1.getMessage());
> > > > >         request.setAttribute("errors", "File
> > Not
> > > > > Found.");
> > > > >      }
> > > > >      catch ( IOException ioe ) {
> > > > >         logger.error(ioe);
> > > > >         logger.info(ioe.getMessage());
> > > > >         request.setAttribute("errors", "Error
> > > > reading
> > > > > file.");
> > > > >      }
> > > > >      return "";
> > > > >   }
> > > > >
> > > > >
> > > > >
> > > > > After the user clicks on the commandLink, the
> > page
> > > > I'm
> > > > > working on, gets refreshed and at the top of
> > it
> > > > > appears the text of the file I tried to
> > download.
> > > > This
> > > > > is not the expected behaviour, what should I
> > do?
> > > > >
> > > > > thanks a lot,
> > > > > Johnny
> > > > >
> > > > >
> > __________________________________________________
> > > > > Correo Yahoo!
> > > > > Espacio para todos tus mensajes, antivirus y
> > > > antispam
> > > > > ¡gratis!
> > > > > Regístrate ya - http://correo.yahoo.es
> > > > >
> > > > >
> > __________________________________________________
> > > > > Correo Yahoo!
> > > > > Espacio para todos tus mensajes, antivirus y
> > > > antispam ¡gratis!
> > > > > Regístrate ya - http://correo.yahoo.es
> > > > >
> > > >
> > >
> > >
> > > __________________________________________________
> > > Correo Yahoo!
> > > Espacio para todos tus mensajes, antivirus y
> > antispam
> > > ¡gratis!
> > > Regístrate ya - http://correo.yahoo.es
> > >
> > > __________________________________________________
> > > Correo Yahoo!
> > > Espacio para todos tus mensajes, antivirus y
> > antispam ¡gratis!
> > > Regístrate ya - http://correo.yahoo.es
> > >
> >
> >
> > --
> > Matthias Wessendorf
> > Aechterhoek 18
> > 48282 Emsdetten
> > blog: http://jroller.com/page/mwessendorf
> > mail: mwessendorf-at-gmail-dot-com
> >
>
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam
> ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: Sending a file to ServletContext Response failure

Posted by Johnny Gonzalez <jo...@yahoo.es>.
Hello Matthias,

I'd like to, but I have no idea where to put it on the
wiki, Where do you recommend me to post it?

Do I need a password for doing so?

Thanks a lot,
Johnny
 --- Matthias Wessendorf <ma...@apache.org> escribió:

> Johnny,
> 
> this has been asked a lot. So since you got a nice
> hint,
> can you bring it to our wiki page ([1]).
> 
> Would be great!
> 
> Thx,
> Matthias
> 
> [1] http://wiki.apache.org/myfaces
> 
> On 6/12/06, Johnny Gonzalez
> <jo...@yahoo.es> wrote:
> > Hello CD,
> >
> > Thanks a lot, that worked perfect :-D
> >
> > Johnny
> >  --- CD <dc...@gmail.com> escribió:
> >
> > > Johnny,
> > >
> > > Try setting the header for the response:
> > >
> > > response.setHeader("Content-disposition",
> > > "attachment; filename="+filename);
> > >
> > > Regards,
> > > CD
> > >
> > >
> > > On 6/12/06, Johnny Gonzalez
> > > <jo...@yahoo.es> wrote:
> > > >
> > > > Hello everybody,
> > > >
> > > > I have to send a file to the response for the
> > > browser
> > > > to show a save/open file dialog box to the
> user,
> > > so
> > > > he/she can download it and save in in his/her
> > > local
> > > > file system. As expected the file is stored in
> a
> > > > specific directory in the file system of the
> > > server.
> > > >
> > > > What I did was to call this method within a
> > > > commandLink component:
> > > >
> > > > public String downloadDB(){
> > > >      FacesContext context =
> > > > FacesContext.getCurrentInstance();
> > > >
> > > >      HttpServletRequest request = (
> > > > HttpServletRequest )
> > > >
> > > > context.getExternalContext().getRequest(  );
> > > >      HttpServletResponse response =
> > > >         ( HttpServletResponse )
> > > > context.getExternalContext().getResponse();
> > > >
> > > >      String filePath = null;
> > > >      int read = 0;
> > > >      byte[] bytes = new byte[1024];
> > > >
> > > >      filePath = getMyDBPath();
> > > >
> > > >     
> response.setContentType("application/pdf");
> > > >      FileInputStream fis = null;
> > > >      OutputStream os = null;
> > > >
> > > >      try {
> > > >         fis = new FileInputStream(new
> > > > File(filePath));
> > > >         os = response.getOutputStream();
> > > >         while((read = fis.read(bytes)) != -1){
> > > >            os.write(bytes,0,read);
> > > >         }
> > > >         os.flush();
> > > >         os.close();
> > > >      }
> > > >      catch ( FileNotFoundException e1 ) {
> > > >         logger.error(e1);
> > > >         logger.info(e1.getMessage());
> > > >         request.setAttribute("errors", "File
> Not
> > > > Found.");
> > > >      }
> > > >      catch ( IOException ioe ) {
> > > >         logger.error(ioe);
> > > >         logger.info(ioe.getMessage());
> > > >         request.setAttribute("errors", "Error
> > > reading
> > > > file.");
> > > >      }
> > > >      return "";
> > > >   }
> > > >
> > > >
> > > >
> > > > After the user clicks on the commandLink, the
> page
> > > I'm
> > > > working on, gets refreshed and at the top of
> it
> > > > appears the text of the file I tried to
> download.
> > > This
> > > > is not the expected behaviour, what should I
> do?
> > > >
> > > > thanks a lot,
> > > > Johnny
> > > >
> > > >
> __________________________________________________
> > > > Correo Yahoo!
> > > > Espacio para todos tus mensajes, antivirus y
> > > antispam
> > > > ¡gratis!
> > > > Regístrate ya - http://correo.yahoo.es
> > > >
> > > >
> __________________________________________________
> > > > Correo Yahoo!
> > > > Espacio para todos tus mensajes, antivirus y
> > > antispam ¡gratis!
> > > > Regístrate ya - http://correo.yahoo.es
> > > >
> > >
> >
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y
> antispam
> > ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y
> antispam ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
> 
> 
> -- 
> Matthias Wessendorf
> Aechterhoek 18
> 48282 Emsdetten
> blog: http://jroller.com/page/mwessendorf
> mail: mwessendorf-at-gmail-dot-com
> 


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam
¡gratis! 
Regístrate ya - http://correo.yahoo.es 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.es 

Re: Sending a file to ServletContext Response failure

Posted by Matthias Wessendorf <ma...@apache.org>.
Johnny,

this has been asked a lot. So since you got a nice hint,
can you bring it to our wiki page ([1]).

Would be great!

Thx,
Matthias

[1] http://wiki.apache.org/myfaces

On 6/12/06, Johnny Gonzalez <jo...@yahoo.es> wrote:
> Hello CD,
>
> Thanks a lot, that worked perfect :-D
>
> Johnny
>  --- CD <dc...@gmail.com> escribió:
>
> > Johnny,
> >
> > Try setting the header for the response:
> >
> > response.setHeader("Content-disposition",
> > "attachment; filename="+filename);
> >
> > Regards,
> > CD
> >
> >
> > On 6/12/06, Johnny Gonzalez
> > <jo...@yahoo.es> wrote:
> > >
> > > Hello everybody,
> > >
> > > I have to send a file to the response for the
> > browser
> > > to show a save/open file dialog box to the user,
> > so
> > > he/she can download it and save in in his/her
> > local
> > > file system. As expected the file is stored in a
> > > specific directory in the file system of the
> > server.
> > >
> > > What I did was to call this method within a
> > > commandLink component:
> > >
> > > public String downloadDB(){
> > >      FacesContext context =
> > > FacesContext.getCurrentInstance();
> > >
> > >      HttpServletRequest request = (
> > > HttpServletRequest )
> > >
> > > context.getExternalContext().getRequest(  );
> > >      HttpServletResponse response =
> > >         ( HttpServletResponse )
> > > context.getExternalContext().getResponse();
> > >
> > >      String filePath = null;
> > >      int read = 0;
> > >      byte[] bytes = new byte[1024];
> > >
> > >      filePath = getMyDBPath();
> > >
> > >      response.setContentType("application/pdf");
> > >      FileInputStream fis = null;
> > >      OutputStream os = null;
> > >
> > >      try {
> > >         fis = new FileInputStream(new
> > > File(filePath));
> > >         os = response.getOutputStream();
> > >         while((read = fis.read(bytes)) != -1){
> > >            os.write(bytes,0,read);
> > >         }
> > >         os.flush();
> > >         os.close();
> > >      }
> > >      catch ( FileNotFoundException e1 ) {
> > >         logger.error(e1);
> > >         logger.info(e1.getMessage());
> > >         request.setAttribute("errors", "File Not
> > > Found.");
> > >      }
> > >      catch ( IOException ioe ) {
> > >         logger.error(ioe);
> > >         logger.info(ioe.getMessage());
> > >         request.setAttribute("errors", "Error
> > reading
> > > file.");
> > >      }
> > >      return "";
> > >   }
> > >
> > >
> > >
> > > After the user clicks on the commandLink, the page
> > I'm
> > > working on, gets refreshed and at the top of it
> > > appears the text of the file I tried to download.
> > This
> > > is not the expected behaviour, what should I do?
> > >
> > > thanks a lot,
> > > Johnny
> > >
> > > __________________________________________________
> > > Correo Yahoo!
> > > Espacio para todos tus mensajes, antivirus y
> > antispam
> > > ¡gratis!
> > > Regístrate ya - http://correo.yahoo.es
> > >
> > > __________________________________________________
> > > Correo Yahoo!
> > > Espacio para todos tus mensajes, antivirus y
> > antispam ¡gratis!
> > > Regístrate ya - http://correo.yahoo.es
> > >
> >
>
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam
> ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.yahoo.es
>


-- 
Matthias Wessendorf
Aechterhoek 18
48282 Emsdetten
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: Sending a file to ServletContext Response failure

Posted by Johnny Gonzalez <jo...@yahoo.es>.
Hello CD,

Thanks a lot, that worked perfect :-D

Johnny
 --- CD <dc...@gmail.com> escribió:

> Johnny,
> 
> Try setting the header for the response:
> 
> response.setHeader("Content-disposition",
> "attachment; filename="+filename);
> 
> Regards,
> CD
> 
> 
> On 6/12/06, Johnny Gonzalez
> <jo...@yahoo.es> wrote:
> >
> > Hello everybody,
> >
> > I have to send a file to the response for the
> browser
> > to show a save/open file dialog box to the user,
> so
> > he/she can download it and save in in his/her
> local
> > file system. As expected the file is stored in a
> > specific directory in the file system of the
> server.
> >
> > What I did was to call this method within a
> > commandLink component:
> >
> > public String downloadDB(){
> >      FacesContext context =
> > FacesContext.getCurrentInstance();
> >
> >      HttpServletRequest request = (
> > HttpServletRequest )
> >
> > context.getExternalContext().getRequest(  );
> >      HttpServletResponse response =
> >         ( HttpServletResponse )
> > context.getExternalContext().getResponse();
> >
> >      String filePath = null;
> >      int read = 0;
> >      byte[] bytes = new byte[1024];
> >
> >      filePath = getMyDBPath();
> >
> >      response.setContentType("application/pdf");
> >      FileInputStream fis = null;
> >      OutputStream os = null;
> >
> >      try {
> >         fis = new FileInputStream(new
> > File(filePath));
> >         os = response.getOutputStream();
> >         while((read = fis.read(bytes)) != -1){
> >            os.write(bytes,0,read);
> >         }
> >         os.flush();
> >         os.close();
> >      }
> >      catch ( FileNotFoundException e1 ) {
> >         logger.error(e1);
> >         logger.info(e1.getMessage());
> >         request.setAttribute("errors", "File Not
> > Found.");
> >      }
> >      catch ( IOException ioe ) {
> >         logger.error(ioe);
> >         logger.info(ioe.getMessage());
> >         request.setAttribute("errors", "Error
> reading
> > file.");
> >      }
> >      return "";
> >   }
> >
> >
> >
> > After the user clicks on the commandLink, the page
> I'm
> > working on, gets refreshed and at the top of it
> > appears the text of the file I tried to download.
> This
> > is not the expected behaviour, what should I do?
> >
> > thanks a lot,
> > Johnny
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y
> antispam
> > ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
> > __________________________________________________
> > Correo Yahoo!
> > Espacio para todos tus mensajes, antivirus y
> antispam ¡gratis!
> > Regístrate ya - http://correo.yahoo.es
> >
> 


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam
¡gratis! 
Regístrate ya - http://correo.yahoo.es 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.es