• Post Reply Bookmark Topic Watch Topic
  • New Topic

Opening files in jsp  RSS feed

 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends i am trying to open an excel sheet in a jsp page using a pop up window, when i try to open using file:///
it opens in local browser but not from remote machines.
when i use say
myapp/webcontent/file.xls it says path not found can you please lemme know what to enter in window.open(what?)

i mean how to specify path


Also i am generating excel sheet dynamically
that means users are saving data into excel as well as database
so when i save first time it works and if the pop up is working(in local browser) it shows properly.
now when i close the pop up and i save again the save to excel fails as EXCEL.EXE is still running in background even though pop is closed
.
Please help its really troubling me
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the file is within the webapp's directory structure, all you need to do is provide a hyperlink to it. If not, you'll need to write a servlet that streams the file to the browser. This is not difficult.
We have an example application that streams binary files in our CodeBarn under the Servlets section.
 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry but i didn't get your answer
can you first have a look at my question
i understand i need to give right path its the right path but still not working
Also i want to know why excel.exe keeps tunning in background even when the pop up is closed
thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sameer sood:
sorry but i didn't get your answer

What part didn't you understand?

Originally posted by sameer sood:
can you first have a look at my question

I looked at your question before answering the first time.

Originally posted by sameer sood:
i understand i need to give right path its the right path but still not working

"not working" is, for the most part, a useless statement.
How are you creating your Excel sheet?
Is it really an Excel file or just a character delimited text file?
How are you getting it to the browser?
Can you post some code?
What is happening when you try to run your code?
Without some meaningful details, nobody is going to be able to give you any meaningful answers.

Originally posted by sameer sood:
Also i want to know why excel.exe keeps tunning in background even when the pop up is closed
thanks

This is a browser issue.
JSP runs on the server.
There is a limit as to what you can control from the server.
Again, without knowing what you're doing, we can't really tell you how to fix this issue (if it can even be fixed).
 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you creating your Excel sheet?

I am creating it using apache.poi API as i should be
it gets created properly


Is it really an Excel file or just a character delimited text file?

It is a proper excel sheet

How are you getting it to the browser?

i am getting to the browser

with a javascript method as i mentioned earlier
window.open("path");



Can you post some code?

the only code dealt here is window.open
and when writting to excel i use



What is happening when you try to run your code?

my code runs fine it writes to the file and it gets saved all I/O locks are released, when window.open(url) opens the new pop up from a button click.
it opens up if i mention c:\\path
but not when a mention a relative path
webcontent/filename
the file:/// thing does not work when remote machines access becoz of security issues

Now in any case if it opens
i can see it right
but when i close the pop up window and try writing to excel sheet again on save, it cannot save changed to excel
The reason by my investigation is that excel.exe is still running in the task manager and i need to end it manually on doing so the excel can be written to again.

Hope i am a clear enough.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you're using POI to write the file (Excel sheet) to the server's file system. You then want to download it to the user's machine using window.open(..).

Using window.open("c:\\.....") will cause the browser to look on the local machine for the file. This, of course will only work if the user is sitting at the same machine where you're running your web server.

Is the file being created in a directory that is accessible to the web?
If so, you should be building a link that is relative to the root of the web application.
See:
http://faq.javaranch.com/java/ResourceUrlProblems to learn how to do this.

If the file is not being written a location within the webapp, you'll need to write a servlet that can stream it to the user's browser.
We have an example application that does this in our CodeBarn under the servlet section.
 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i understand the relative part thing
Though i didn't knew anything about streaming

In fact that was the question when i say
/MyApp/WebContent/filename
its a relative path to my app
but the file though being there it says resource not found
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read:
http://faq.javaranch.com/java/ResourceUrlProblems
?

If so, what part are you stuck on?
We have another FAQ entry that pretty much covers the same thing but was written by a different person.
http://faq.javaranch.com/java/RelativeLinks
Maybe that one will work better for you.
 
sameer sood
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok
that was a path problem am still not clear but without any path it worked
any how the excel.exe prob remains still there i am still not clear how to do streaming can you please show me a link which explains what is it and how it does so??
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!