• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem download file.

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Here is the code snipet from one of the actions wherein i'm creating a tem file and setting its path to request attribute . In jsp getting the attribute and forwarding the response .

This is working fine with local and remote machine both when I run it in WSAD , but same is not working for Tomcat5.0 and JBoss ..
Help pls.

================
And the jsp part is




Thanks.

Naveen
 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh ..
This is also there in action after getting the forwardURL string.


Thanks..
 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi...
Seems I could not explain my problem proerly.
Trying to redefine it ...
main target is to "let the user download (open or save ) the file just created in the server".

The code sent in prev post is able to do this on WSAD (5.1) but causing problem( requseted resorce is not found...) on Tomcat and Jboss .

I'm running the full application on tomcat but deploying only the .war file on JBoss..

Hope , I've made it more clear this time..

Thanks.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A URL that begins with "file://" only works on the local file system. It will not work on a server. This prefix should never be used in a web application. The only reason it worked with WSAD is that your server and browser were both on the same system.

Here are two possible solutions:

1- (Preferred) Don't output to a file at all. Simply retrieve the HttpServletResponse object's OutputStream using its getOutputStream() method and then write to it instead of the FileOutputStream. You would then set the content type using response.setContentType() method. Make sure you return null from the execute() method of your Action class to let struts know that you've handled the response and don't need it to forward to a JSP.

2- Create a temporary file in the web application's context so that it is available to be downloaded. You can find the actual file path of the web context with the following statement:

String path = getServlet().getServletContext().getRealPath("/");

Once you have this path, you can write your file to it. The user can then access it the same as any other file in your context:

http://myserver.com/myApp/myfile.xls

The advantage of option 1 over option 2 is that you're not cluttering up the disk of your server with files that you need to keep track of and clean up periodically.
 
Naveen Mishra
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Merrill for ur response.



The only reason it worked with WSAD is that your server and browser were both on the same system.


but , I was able to download the file from remote system as well. that is what to my surprise , how come it worked (and still working ) with WSAD ?

thanks , anyway, for your support.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All I can tell you is that a URL of file:///xyz/abc/myfile refers to a file on the same file system as your browser. If you developed the app in WSAD and then ported it to a server, what you're getting when you think you're downloading the file from the server is the file on your local system that you created while you were testing on the local system. If you delete this file from your local file system, it will stop working.
 
reply
    Bookmark Topic Watch Topic
  • New Topic