Servlet controlled download question

I've written a servlet that will extract my file from the database and prompt the client browser with a "Save As" prompt. So far so good.
The problem I'm having is that for the file name, the browser is using the name of the servlet (say Example.do" as the file name.
So the box shows the following
Filename : Example
File Type:
From: www.examplehost.com
So my question is how to I get the correct file name to show up, and get the file type field populated. I'm trying to get this to work for the IE 5 browsers.
The headers are being set as follows:
response.setContentType("application/x-download; name=\"" + fileName + "\"");
response.setHeader("Content-Disposition","attachment; filename=" + fileName + ";");
Any help would be appreciated. Thanks
Sean

That problem is due to the fact that the browser sets the name of the file equal to the request.
There are two solutions i can imagine :
- Place the file in a public place (Where you have your jsp and such) :
Cons : Anyone that knows the file is there may get it.
A big security error, specially if the file is confidencial.
Pros : The file name will be the correct one.
- Use an applet that connects to the servlet :
Cons : It may take too long to load
Many ppl don't like applets running on they're machine
pros : You may create you own progress bar, with percentage and everything;
You control the time it takes and the speed you wish it to use;
The best of all, You may copy the file into a temp dir and then transfer it to the dest dir with the name you wish or the user wishes.
It's up to you to decide,
Daniel Campelo

Similar Messages

  • Activex view/print control downloads

    Currently running SAP Business Objects Enterprise XI R2 in a production environment. We have installed and are testing Enterprise 3.1 and will all likelihood will move this new version into production this upcoming weekend (7/17) and shut down XI R2.
    I would love it if someone could PLEASE explain what triggers the whole activex view and print control downloads. This has to be the most frustrating thing with BO product.
    Here's the deal. Sometimes it prompts for download, sometimes it does not. Yes, all the activex security controls and plug-in settings are activated properly (ie: prompting for activex download are either enabled or set to prompt). We have a fair number of users who do NOT have local admin rights on their PC's so we were worried we'd have to figure out how to push out the controls. Yet, in testing 3 separate machines (using the new 3.1 release), none of them got prompted for downloads and they were still able to view and/or print reports using activex. I was led to believe that with the new release (3.1), it would be like viewing or printing for the first time and download/install of activex controls would be required. Is that bad information? Does it use the 11.5 activex add-on's that are already installed for current production system instead?
    Bottom line, I have seen it prompt on some machines and not on others. All machines are actively using the XI R2 production system also. I just have them use a differnt link to test the 3.1 release. So, what triggers the request for download? Why do some users get the prompt and others don't?

    Why are you doing this with BO4 just released?
    the issue of active X depends on
    the version of IE
    the settings of download ActiveX
    IF the Active X download have already happened
    some of these may already be on web sites used have already downloaded (nothing to do with CR)

  • Open File Dialog appears TWICE when using servlet to download an attachment

    Hi,
    This is KILLING me!!! Please HELP.....
    I am using a servlet to download an xml file, which I build on the fly based on user interaction.
    The open file dialog appears nicely and I hit open. The dialog pops up again immediately and I have to click open again in order to open the file.
    This works fine when file extension is txt and I DONOT have to click twice. Here is the code:
    String xmlString = getXMLString(); //builds xml
    String fileName = "myFile.xml";
    response.setContentType("application/x-download");
    response.setHeader("Content-disposition", "attachment;filename=" +fileName);
    PrintWriter out = response.getWriter();
    out.print(xmlString);
    out.flush();
    I am using IE6.0 sp2

    http://forums.java.sun.com/thread.jspa?threadID=596940&tstart=20

  • Does Servlets support downloading resuming

    Hi Everyone,
    In my project, I am using servlets for downloading .exe files from an application. Here I am using servlets to open the required file and stream its contents to the response object.
    Now, I want to give my users the ease of downloading big files of 91 MB in parts. Since one cannot downloading such a big file in ine shot as there may be network failures etc.,. I have installed download manager in my machine. But I can download only a part of the software. I am not able to resume from the part where I stopped last session.
    Can any one suggest how can we write servlets to support download resuming.

    Errata: the servlet has to set the "Content-Range" field, whereas the client seems to use "Range" and (maybe) "If-Range". See the following for definitions and examples:
    http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

  • Servlet for downloading a file

    i am writing a servlet for downloading a file on a GET action in the form..the web-xml is deployed correctly as far as i can interpret..bt i am encountering an error during the run time..
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    here is the log file..
    Jul 11, 2008 12:07:14 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet DwnFile threw exception
    java.lang.NullPointerException
         at com.example.web.dwnfile.doGet(dwnfile.java:17)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    it has some more content bt it is just the exceptions thrwn...
    and here is my *.java file*
    package com.example.web;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class dwnfile extends HttpServlet
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    response.setContentType("/image/jpeg");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/2004.jpeg");
    int read=0;
    byte[] bytes=new byte[1024];
    OutputStream os=response.getOutputStream();
    while ((read=is.read(bytes))!=-1)
    {os.write(bytes,0,read);
    os.flush();
    os.close();
    the bold line is whre the exception is pointing..i think..
    thanks in advance..
    Edited by: Sun_Rockz on Jul 10, 2008 7:13 PM

    response.setContentType("/image/jpeg");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/2004.jpeg");there was an error in this part of code..the image extension of .jpeg is not allowed it seems..on changing it to jpg worked..and
    in the first line the contenttype mst not be preceded by a forward slash..
    now one more doubt relating to the same servlet..
    response.setContentType("application/x-zip");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/servlet_spec.zip");
    if i keep this in my servlet the required action is taking place..i.e.i am gettin a download option bt the problem is tht the file is getting downloaded as a download.do file.....
    download.do is the url pattern tht i am using in my html web page..
    i tried replacing different types of allplications and files bt all are downloaded wit the same name. i.e. download.do
    so what do u think is reason behind this..
    thanks for all the replies.
    Edited by: Sun_Rockz on Jul 11, 2008 10:47 AM
    Edited by: Sun_Rockz on Jul 11, 2008 10:51 AM

  • Controlling model questions

    Dear SAP Guru's,
    Kindly provide me Controlling Model Question papers. My Controlling cetificqation is on 26th June. Removed by Moderator
    Humbly request you to help me.
    Thanks
    Deepak
    Edited by: Lakshmipathi on Jun 20, 2010 7:33 PM
    Dont deviate the forum rules by asking to share the information to personal mail id

    me too, but I was so deceived not to found Model questions that I just did not resist posting "anything" about the MODEL clause !
    well, to find sample question, just go to the oracle certification homepage than you will find selftestsoftware.
    However, revealing content of the exams is not allowed and nobody will do that here...

  • Flat File and Control Files Questions

    Greetings,
    I've worked with Oracle for about 10 years, but have little experience with using sql-loader.
    I have data from Visual FoxPro tables going into Oracle 10g via a Perl script. I am having issues and therefore have a couple questions.
    1) If the data from my foxpro table is basically everything in the table as in 'Select * from table-name', does the control file have to list every column that is in the FoxPro table?
    -- I have a case where a FoxPro table has 15 columns but we are trying to upload only 10 columns. The script is dynamic. It selects * from each FoxPro table and creates a Flat File for each on the fly. Then sql-loader uploads the data to Oracle. The Flat File for this one table has data from all 15 columns, but the Control File only lists 10 of the columns to be uploaded into Oracle.
    2) Do the column names in the control file 'have' to match both the column names in the FoxPro table and the Oracle table, or only the Oracle table?

    YankeeFan wrote:
    Greetings,
    I've worked with Oracle for about 10 years, but have little experience with using sql-loader.
    I have data from Visual FoxPro tables going into Oracle 10g via a Perl script. I am having issues and therefore have a couple questions.
    1) If the data from my foxpro table is basically everything in the table as in 'Select * from table-name', does the control file have to list every column that is in the FoxPro table?
    -- I have a case where a FoxPro table has 15 columns but we are trying to upload only 10 columns. The script is dynamic. It selects * from each FoxPro table and creates a Flat File for each on the fly. Then sql-loader uploads the data to Oracle. The Flat File for this one table has data from all 15 columns, but the Control File only lists 10 of the columns to be uploaded into Oracle.
    Yes - use the FILLER spec to ignore columns you do not care about - http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#sthref946
    2) Do the column names in the control file 'have' to match both the column names in the FoxPro table and the Oracle table, or only the Oracle table?Only the Oracle table.
    HTH
    Srini

  • Apple mail - how to control downloading?

    My question is about apple mail, not safari.
    I'm downloading some files sended to me by mail.
    They're some links to ftp. I use the right click of the mouse and "save object".
    How can I control or interrupt the process? It seems impossible!
    Thanks!

    Mail - Preferences - View - turn off Classic Layout. At least that works for 10.8 (this forum), I don't recall if the same thing applies for 10.7 (your profile).
    Matt

  • Iplanet/Servlet Forwarding Issue/Question

    Scenario:
    A directory is protected using Iplanet web server access control (Iplanet Directory Server). User accesses the directory and enters valid user name and password. User is authenticated OK. The file is then posted to a servlet which does a forward to another page in the same directory. The page is not displayed due to a problem with authentication. Code to forward is as follows:
    getServletConfig().getServletContext().getRequestDispatcher(response.encodeURL(pageName)).forward(request,response);
    I check request.getUserPrincipal().getName() and
    request.getRemoteUser(). The first returns the username that iWS is running under, the second returns
    null. Is there a correct way of doing this to avoid the forward from failing.

    requiem wrote:
    Question to BT
    Hello i have recently joined BT Infinity and have hit the issue of the Port Forwarding not working. My HH3 is on the following version of software. Will this version automatically upgrade to the latest version of firmware and will this fix my port forwarding issue?.........
    Thank you
    Dean.
    Current firmware:
    V100R001C01B031SP09_L_B
    Last updated:
    Unknown
    Hi Dean
    By the look of it you've got the type B version of the HH3 with current firmware.
    From http://bt.custhelp.com/app/answers/detail/a_id/13073
    The latest versions of the firmware are:
    BT Home Hub 3 – Software version 4.7.5.1.83.8.57.1.3 (Type A) or V100R001C01B031SP09_L_B
    Please Click On any Text in Blue as that automatically links to information.
    PC (NDEGR)

  • Setting default filename for servlet-based download

    I'm new to servlet programming and am attempting to download a file from the server to the client. When I am prompted to open the file from it's current location or save it to disk, the correct filename appears. However, when I click ok and the Save dialog appears, the default filename isn't the actual name of the file but instead contains the name of the package the servlet is located in. Can anyone tell me how I can change my code to have the default filename appear instead of the package name. Thanks.
    Here is the code to call the servlet located in the package named 'frosttwo':
    WebgapBeanFactory wgbf = WebgapBeanFactory.getWebgapBeanFactory();
    String path = wgbf.getTransferFileDirectory();
    String filename = path + request.getParameter("file");
    System.out.println(filename);
    response.sendRedirect("/servlet/frosttwo.Servlet1?file=" + filename);
    Here is the code contained in the servlet:
    public class Servlet1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    /**Initialize global variables*/
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    /**Process the HTTP Get request*/
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String file = null;
    try
    file = URLDecoder.decode(request.getParameter("file"));
    String filename = file.substring((file.lastIndexOf(File.separatorChar) + 1), file.length());
    response.setContentType("application/octet-stream");
    response.setHeader("Content-disposition", "attachment;filename=" + filename);
    File f = new File(file);
    FileInputStream is = new FileInputStream(f);
    ServletOutputStream s = response.getOutputStream();
    byte[] buffer=new byte[8192];
    int length=buffer.length;
    while((length=is.read(buffer))!=-1)
    s.write(buffer,0,length);
    s.flush();
    catch (IOException ex)
    System.err.println("There was an error sending file " + file);
    ex.printStackTrace();
    catch (Exception ex)
    System.err.println("There was an error sending file " + file);
    ex.printStackTrace();
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
    /**Clean up resources*/
    public void destroy() {
    Thanks again.

    I use something like this for res.setHeader and it works fine for me. In the save dialog box it puts this filename there. But if its not able to find the filename then sometime it used to put servletname instead of filename:
    res.setHeader("Content-Disposition","multi-part attachment;filename=\""+
    fname+"\";");
    hope it helps
    vinod

  • HELP - Dial Up Download Question from a Mac Mini Tiger OS X 10.4.6 Newbee??

    There are hugh download files (133 Mb for 10.4.7 for example) that appeared when I ran Software update the first day I got my Mini. This would require 10 to 12 hours download on my Juno account. One solution I saw in these forums was to have a neighbor with High Speed connection download and burn a disc. My NEWBEE question is... Can you go to the Apple OS X download page and successfully download the 10.4.7 update (and others) using a Windows machine with Windows software?? Then have that Windows PC burn a disc that can transfer the update to my Mini?? I'm breaking new ground in my neighborhood and appear to be the only one with a Mac. These forums are great - Thanks Addie
    mac mini   Mac OS X (10.4.6)   first time user

    Thanks to you and Sig for the response. We have NO APPLE STORE/OUTLET within a four hour drive, therefore your input that a PC can burn the disc is the best alternative I have. BUT what do you mean by a "hybrid" data CD? I'm a NEWBEE, so could you give me a little more specifics, i.e., what package/brand & model should I buy? I was thinking any CD-ROM would work! Thanks & sorry for my lack of experience, Addie

  • Servlet Registration/Forwarding Question in WLS 5.1 SP8

              Here is my problem....
              The request coming to WL server is http://localhost:7003/?id=11
              How do I configure weblogic so that it sends the all these requests(starting with
              a '?')
              to a particaular Servlet?
              (I know how to set up a servlet to handle all html rquests..
              weblogic.httpd.register.*.html=com.mydomain.web.MyServlet)
              Any help would be appreciated.
              Thanks,
              

    You'll have to bind "/" to the selected servlet in the web.xml.
              Peace,
              Cameron Purdy
              Tangosol Inc.
              << Tangosol Server: How Weblogic applications are customized >>
              << Download now from http://www.tangosol.com/download.jsp >>
              "Kailu" <[email protected]> wrote in message
              news:3b781f99$[email protected]..
              >
              > Here is my problem....
              > The request coming to WL server is http://localhost:7003/?id=11
              >
              > How do I configure weblogic so that it sends the all these
              requests(starting with
              > a '?')
              > to a particaular Servlet?
              > (I know how to set up a servlet to handle all html rquests..
              > weblogic.httpd.register.*.html=com.mydomain.web.MyServlet)
              >
              > Any help would be appreciated.
              >
              > Thanks,
              

  • Oracle 9i AS Portal download questions

    I read the installation guide for Oracle 9iAS (the guide for all of AS, not just the Portal component). I have some questions that were not addressed in the documentation.
    1) Do you need to download the entire Oracle9i Application Server in order to download and access the Oracle Portal component? I understand there's three levels of downloads (minimal, standard, and enterprise), and that even the minimal edition contains Oracle 9iAS. However, I was hoping to minimize space and memory required when working with Oracle Portal. (I just need to configure databases and manage database security, both of which can be done using Oracle Portal.)
    2) I already have Microsoft Peer Web Services installed on my computer. (That's the development environment in which you can test Cold Fusion and ASP code.) Will this conflict with the Oracle 9iAS, since both are servers that may affect, or be affected by, network configurations - even if they're both in a local, standalone test environment?
    (I can't just remove PWS since I do need it for testing Cold Fusion and/or ASP development code.)
    3) I understand that in order to download Oracle 9iAS, I need to already have access to an Oracle database. What mimimum version of Oracle do I need to be working with? The installation guide states that I can find out more information about database requirements at http://metalink.oracle.com. However, I can't even register for this site in order to access it, because it requires a "Support Identifier (CSI, SAC, Access Code etc.)" However, the CSI for the company where I work has expired - so I can't access that area for info.
    It seems that I may need to use Oracle 8i. I just downloaded the Installation Guide for the Oracle 8i Personal Edition. Would that be sufficient to work with a standalone (personal edition/evaluation copy) of Oracle9i AS?
    I hope to hear from someone soon about these issues! Thanks.

    1)Portal is an integrated component of 9iAS. You need to download all of 9iAS and select the minimal install option.
    2)We haven't tested this configuration, but as long as you set up apache appropriately to use different ports than the existing software it should work.
    3)Portal requires 8.1.6.2 Enterprise edition or 8.1.7 Standard edition. Personal Edition will not work.

  • Sql loader control file question.

    I have a text file (t.txt) which contains a record types AAA and AAB to input fixed width data into a table (t) AAA_NO, AAA_TYPE, AAB_DESC.
    Control file (control_t) contents:
    load data infile '/path/t.txt'
    insert into table t
    when ((1:3) = 'AAA' )
    AAA_NO position (4:14) CHAR,
    AAA_TYPE postion (15:27) CHAR
    Works prefectly, but I need to add another set of data from the same t.txt file with record type AAB. I attempted to add this into the same control file:
    into table t
    when (1:3) = 'AAB'
    AAB_DESC position (28:128) CHAR
    It fails naturally. How would I include the addtional record type data into the same table after AAA_NO and AAA_TYPE have already been inserted? Do I need to include the AAA_NO in the second insert (AAB_DESC)? Should I create another temp table to store only the AAA_NO and AAB_DESC and then insert that data into table t after the loader is done? Or can this be completed in the same control file?

    Thanks again for the assistance, this is a tough one to fix. I am new to sqlloader.
    The temp table creation is causing some serious errors, so I am back to trying to fix sqlloader to get the job done. the apt.txt file contains records that each row of a new record starts with either 'APT' or 'ATT'. Here is the details of what I am trying to do.
    crtl file:
    load data
    infile '/path/apt.txt
    insert
    into table t_hld
    when ((1:3) = 'APT')
    apt_no position (4:14) CHAR,
    apt_type position (15:27) CHAR,
    apt_id position (28:31) CHAR
    The next section is the problem where I am inserting apt_sked into the same table t_hld as above because it has a different record qualifier its ATT and not APT.
    insert
    into table t_hld
    when (1:3) = 'ATT'
    apt_no position (4:14) CHAR,
    apt_sked position (16:126) CHAR
    The positions of the data using fixed is working, I can insert the apt_sked data into another temp table instead of t_hld and it works. It's just when I attempt to place the ATT apt_sked data into the t_hld table after the APT data has been loaded into the t_hld table....I tried APPEND instead of INSERT, but that does not work.
    The APT_NO's of the data are all the same- it is the qualifier for the records (Primary Key attribute- however I do not have it established since it is a temp table concept).
    I am stuck trying to get the data in the t_hld table, everything works when I do not try to put the ATT apt_sked data into t_hld- everything is valid. And placing the ATT apt_sked data into a different temp table works perfectly- but I can't find a way to create an update to t_hld from this temp table without errors. So I am trying to go back to sqlloader to get this done- any thoughts or questions?
    Thanks a billion!
    Shawn

  • Toolbar Custom Control Ring question

    Hi.  This is probably a dumb question, but how do I add items to a ring (kRing) toolbar item when using the Toolbar Custom Control (toolbar.fp) in CVI 2010?  Thanks.
    Solved!
    Go to Solution.

    Interesting.  I take it that the toolbar items are actually just standard control types and once I have the toolbar's panelhandle and control ID I can manipulate the items as controls with the standard user interface library functions (within reason of course)? 
    In any case, thanks for the help.  That worked perfectly.

Maybe you are looking for

  • HT1923 OS X 10.8.2 and iTunes 11

    I am stymied with my MacBook Pro running OS X 10.8.2 and iTunes 11. Every time I start iTunes, after a few seconds I get the spinning beach ball and have to force quite. I have update to the newest iTunes. Any ideas or suggestions?

  • Connected iPod to my laptop, 4,500 songs deleted

    I used several different apple USB cords and they all recognize my phone, but not my iPod... It just charges and yesterday I plugged it in to add more songs, and EVERYTHING was wiped out.. I plug my iPod into my laptop and its charging but no iPod ic

  • Random disconnections... Without being notified?

    I'm experiencing a very frustrating problem. I can never really seem to stay logged on to AIM for very long regardless of the client I'm using. Here's the kicker, though: I'm never notified that I have been logged off, or that I have lost my connecti

  • Fixed height of text iView

    Hi all, i want to get a text iView into my page with a fixed height, and if the text increases that limit a vertical scroll bar should apear and not the horizontal scroll bar. i am trying to use <iframe> tag in the jsp and call the html page in that

  • RAC Pre-requisite Problem

    I would like to set up a RAC environment between 2 different sites. They are physically seperated in 2 different district. The ISP of machine A used is different from the ISP of machine B used. Do they need to be the same ISP in order to be RAC? if y