users@glassfish.java.net

Re: window.open() script problem in glassfish

From: Ronaldo Rigoni ... <rrigoni_at_gmail.com>
Date: Sun, 11 Oct 2009 23:41:22 -0300

What?
You are trying to open a local file?
c:\\....?
Its not working, only on local machine;
When you invoke window.open("c:\\TEST\\test.xls"); the browser request to a
fileSystem the file, not to a GlassFish.
You can implement a servlet for read the file system and return the response
to the browser.
Eg:

*try*
        {
                // Set the response for our download
               // yourBaseDir = c:\\myFiles\
                File file = *new* File(request.getParameter('file',youtBaseDir));
                *int* fileSize = (*int*)file.length();
                FileInputStream fis = *new* FileInputStream( file );
                // Set the file size of the download....
                resp.addIntHeader("Content-Length", fileSize );
                resp.flushBuffer();
                OutputStream os = resp.getOutputStream();
                //write to out output stream
                *while*(*true*)
                {
                    *int* bytedata = fis.read();

                    *if* (bytedata == -1){
                            *break*;
                    }
                    os.write(bytedata);
                }

                // flush and close streams.....
                fis.close();
                os.flush();
                os.close();
        }
        *catch* (FileNotFoundException e){
                logger.debug("file not found");
        }
        *catch* (IOException e)}
                logger.debug("Unable to get response output stream", e );
        }

 And invoke window.open("yourApp:8080/context/servletDownload/file=yourFile");

Regards




2009/10/11 <glassfish_at_javadesktop.org>

> HI,
> Iam tryign to open a .xsl file from a jsp page, it is not working in
> Glassfish server but if i deploy same code in tomcat it is working.
> Is there any security settings do i need to change in server.
> The code is
> window.open("c:\\TEST\\test.xls");
> if i copy the .xls file to my project folder then iam able to open the file
> in new window.
>
> If anybody knows please suggest me.
>
> thanks a lot.
> Kumar
> [Message sent by forum member 'praveenkumar14' (pravkumar14_at_yahoo.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=367593
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>


-- 
[]'s,
Ronaldo Rigoni
http://www.ronaldorigoni.com.br
Desenvolvedor JEE
Ministério da Educação -  CESPE