This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JBoss/WildFly and the fly likes dowloading file from a server problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "dowloading file from a server problem" Watch "dowloading file from a server problem" New topic
Author

dowloading file from a server problem

Nasir Munir
Greenhorn

Joined: May 31, 2002
Posts: 22
I have this distributive application. I want to allow user to download a file from one of its jsp page. My jsp page checks for the existance of file. If file exists, then I hyperlink them with html linking tag. Someone suggested that I need .xml file in my configuration directory of application server. I did that, and used the folder name as URL source for the hyperlink. It is still not working. Can anyone suggest something ? or guide me in the right direction, as to how can I allow downloading of files from the server?
I am using JBoss 4.0.5.GA and jdk version 1.4.2_11. If I need to explain more about my problem, please let me know. Thanks

here is my .xml file:


here is my jsp code:

and :

[ May 24, 2007: Message edited by: Nasir Munir ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
Using folder names will not work, unless the server is configured to serve an index page of the directory contents. Is that what you are trying to do?
It is still not working.

What does this mean? What is or isn't working as you would expect? It would also help if you posted the HTML that is generated, and describe what happens if you click on the generated link.
if (spec.exists() == true)

This should just be "if (spec.exists())".
[ May 23, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Nasir Munir
Greenhorn

Joined: May 31, 2002
Posts: 22
I meant, when I use the folder name "/Fastran" as declared in the .xml file, I still cannot download the file. When I choose option "save file as..." from the right click menu, the error message suggests that it cannot find the specified file. I have included that .xml file as suggested by someone online and I am not sure if that is right or not.
Is there anyway of allowing downloading a file from an application server? Can I get some directions ?
If I don't use that .xml file, then I have to give the local URL as hyperlink for those files. In this case, I can download files from the same computer where application server is running, but cannot from any other computer.
My question is how to download a file from an application server?
[ May 23, 2007: Message edited by: Nasir Munir ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
A few comments, in no particular order:
  • docBase="/home/jboss-4.0.5.GA/bin/Fastran" - I wouldn't keep web apps in the bin directory - that's for other purposes. Doesn't JBoss have a dedicated directory for applications, like Tomcat has?
  • "If I don't use that .xml file, then I have to give the local URL as hyperlink for those files." Local URLs are a crutch that doesn't work for a real server deployment. That context file tells JBoss where the web app is, and under which URL it should be made available; as soon as it is configured correctly, everything should work fine.
  • The important thing you haven't told us is: what is the URL that is generated in the JSP page? Is it the correct one? What server response code is generated for the access?


  • [ May 23, 2007: Message edited by: Ulf Dittmer ]
    Gregg Bolinger
    GenRocket Founder
    Ranch Hand

    Joined: Jul 11, 2001
    Posts: 15299
        
        6

    The problem is that the file you are trying to link to is not web accessible. So you can't just provide an a href link to it. You can

    1. Copy the file to a web accessible folder and then build the link
    2. Stream the file back to the user which would entail setting the response content type correctly and hoping the user's browser knows what to do.


    GenRocket - Experts at Building Test Data
    Nasir Munir
    Greenhorn

    Joined: May 31, 2002
    Posts: 22
    Thanks for replies guys.
    I understand what you are saying about creating folder within the application server. I have created it outside now, but I still can't download the files. I am getting the same error message ie cannot download from the location, or cannot find the file.
    The URL generated by the JSP page is "/Fastran/path " where path is the follow up folder name from Fastran onwards. ie username/sessionID/files. I am targetting files(for download).
    How to configure JBoss to accomodate that (If I need to tell JBoss which folder is accessible for downloads). I was told to copy that .xml file in "JBoss/server/cofig/Jboss.web/localhost/file.xml" There was no JBoss.web folder, so I created that. For some reason, still in vain. Can anyone shed some light on the configuration of JBoss or else ? thanks a lot again.
    [ May 23, 2007: Message edited by: Nasir Munir ]
    Jaikiran Pai
    Marshal

    Joined: Jul 20, 2005
    Posts: 9924
        
    158

    If i understand your requirement correctly, you are trying to download a file from your application which is deployed on JBoss server. Assuming you want to download a file named somefile.xls, present in your application (lets call it myApp.war), from the server. Here's what you can do:

    - Create your myApp.war

    - Place a file named somefile.xls directly under myApp.war

    - Lets try this simple jsp:



    - Place this jsp (lets call it download.jsp) directly under your myApp.war

    - Deploy the myApp.war to JBoss (this just means that you have to place your myApp.war in the %JBOSS_HOME%/server/default/deploy folder)

    Once deployed, access the download.jsp at http://localhost:8080/myApp/download.jsp

    - Click on the download link that is shown on this jsp.

    That should be it.


    [My Blog] [JavaRanch Journal]
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41062
        
      43
    The URL generated by the JSP page is "/Fastran/path" where path is the follow up folder name from Fastran onwards.

    As pointed out before, you can't "download" a directory. What do you think should happen if a user clicks on a link representing a directory?
    Nasir Munir
    Greenhorn

    Joined: May 31, 2002
    Posts: 22
    I am not pointing out to a directory. There is a file at the end of that path as "ftn07_i". Please see the code posted above. I am listing the important lines again:


    where destFile is :

    and j is just a number of the file. Also getUserEmail() and getSessionId() is the input taken from the login form of the application.
    I have now created a folder outside the scope of JBoss as suggested earlier. Destination files are now situated at C:/Fastran/user/id/file

    If I am creating a download.jsp page, that means I know the files before hand for download purposes. My problem is, I don't know about the file. My application will run and process data and will generate some files(dont know the exact number-depends on the input from the user). Once those files are created, I want them to be presented to the user for review. If the user wants to download them he/she can. If not, then the files will be deleted in the next step.

    [ May 24, 2007: Message edited by: Nasir Munir ]

    [ May 24, 2007: Message edited by: Nasir Munir ]
    [ May 24, 2007: Message edited by: Nasir Munir ]
    Nasir Munir
    Greenhorn

    Joined: May 31, 2002
    Posts: 22
    case solved:
    refer to this article:

    setting context for web applicaton
     
    Don't get me started about those stupid light bulbs.
     
    subject: dowloading file from a server problem
     
    Similar Threads
    The system cannot find the path specified
    Dynamic XML and JSP
    how to disable session time out
    Two questions on " JSP SYNTAX 1.2 " issued by SUN
    unable to download xml file