Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7308525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:34:09+00:00 2026-05-28T23:34:09+00:00

I looked into BalusC’s code for a custom download servlet from absolute path (see

  • 0

I looked into BalusC’s code for a custom download servlet from absolute path (see http://balusc.blogspot.com/2007/07/fileservlet.html#FileServletServingFromAbsolutePath). I’m not a Java Web Developer Expert so I would love if someone can explainme this part of the code

private String filePath;

// Actions ------------------------------------------------------------------------------------

public void init() throws ServletException {

    // Define base path somehow. You can define it as init-param of the servlet.
    this.filePath = "/files";

    // In a Windows environment with the Applicationserver running on the
    // c: volume, the above path is exactly the same as "c:\files".
    // In UNIX, it is just straightforward "/files".
}

When does the init method gets called? Why do we need the filePath to be set in the init method?

I have an XHTML (Mojarra+IceFaces) with something like the code below that works great. My page is missing just the part of downloading the file which is referenced by the outputLink tag

                <ice:tree id="tree"
                          value="#{treeBean.model}"
                          var="item"
                          hideRootNode="false"
                          hideNavigation="false"
                          >
                    <ice:treeNode>
                        <f:facet name="icon">
                            <ice:panelGroup style="display: inline">
                                <h:graphicImage value="#{item.userObject.icon}" />
                            </ice:panelGroup>
                        </f:facet>
                        <f:facet name="content">
                            <ice:panelGroup style="display: inline-block">
                                <ice:outputLink value="#{item.userObject.filePath}">
                                    <ice:outputText value="#{item.userObject.fileName}"/>
                                </ice:outputLink>
                            </ice:panelGroup>
                        </f:facet>
                    </ice:treeNode>
                </ice:tree>

In my Backing bean I have two fields fileName (just the name of the filewith extension e.g. Image.jpeg) and filepath (the ABSOLUTE path of the file in the server). Finally I want to download the file with the custom servelet, how can I do that??

Cheers,

UPDATE

Let’s say mi base-dir is /SRC and under that dir I have all my xhtml pages and the WEB-INF and META-INF and aditionally I have a dir called dataFiles under dataFiles I have the following structure

  --dataFiles
  |----Enterprise1
  |    |--User1
  |    |   |--goodFiles
  |    |   |  |--ok.txt
  |    |   |--badFiles
  |    |      |--bad.txt
  |    |--User2 
  |    |   |--goodFiles
  |    |   |  |--ok.txt
  |    |   |--badFiles
  |    |      |--bad.txt
  |----Enterprise2
       |--User1
       |   |--goodFiles
       |   |  |--ok.txt
       |   |--badFiles
       |      |--bad.txt
       |--User2 
           |--goodFiles
           |  |--ok.txt
           |--badFiles
              |--bad.txt

that’s how I render the tree with IceFaces and I just have the filename in the backing bean (i.e. ok.txt or bad.txt) but I cannot figure out how to download the file pointing by the link in the tree.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:34:10+00:00Added an answer on May 28, 2026 at 11:34 pm

    Well finally got it work.

    First of all thanks to BalusC, there were some posts here that helped me understand but someone delete them. Anyway, here’s what I’ve learned.

    1. In Servlet’s init method the filePath variable must point to the absolute path where the files to download are.
    2. In the web.xml the servlet-map-url-pattern will cause to execute the servlet when the browser has that url pattern.
    3. In the xhtml page tha value of the link should begin with the url-pattern followed by the name (or a path+FileName) so when you click the link the download begins.

    That’s all I had to do !

    In the example of the question, the filePath variable in the servlet’s init method will point to the absolute path, something like C:\myApp\dataFiles
    Then in the xhtml will call the servlet with something like

    <ice:outputLink value="dl/myPath/#{myBean.fileName}>
        <ice:outputText value="#{myBean.fileName}"/>
    </ice:outputLink>
    

    Note 1: that the first part of the value of the outputLink is dl/ this is because the url-pattern for the servlet to download is mapped to it

    Note 2: in the outputLink the value of myPath could be dl/Enterprise1/User1/file1.ext

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looked into: http://www.developerfusion.com/tools/convert/vb-to-csharp/ as well as: http://www.icsharpcode.net/opensource/sd/ but neither does exactly what I
Today, I have looked into HTML code of facebook.com, and found something like this:
I was looking for an object formatter and templater. http://haacked.com/archive/2009/01/14/named-formats-redux.aspx I looked into HenriFormatter
I've looked into Apple's Certificate reference , and I don't see anything about removing
I've looked into COM servers and Windows services but I'm not sure what best
As far as I know (I haven't looked into the django's admin source code
I looked into the code, everything is int -- the parameter passed to CountDownLatch
I've looked into the source code of DBIx::Class recently and found that I don't
From all the NMS(network management solutions) I've looked into, only Zenoss has a daemon
I looked into C:\Program Files\Microsoft.NET and I can't see any SN.exe file. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.