How to skip(do not wnat to get display) save dialogue box for file download

I am having servlet for downlading a file from server. When I call this servelt I am able to get the file from server but I get a save dialog box which I do not want. I want that this file should be stored at a specific location given by me in a servlet.
So haoe I can avoid that save dialog box and where I should specify the specific location?
Thanks in advance
package com.txcs.sms.server.servlet;
import java.io.*;
import java.util.zip.GZIPOutputStream;
import javax.servlet.*;
import javax.servlet.http.*;
public class DownloadServlet extends HttpServlet
    public DownloadServlet()
        separator = "/";
        root = ".";
    public void init(ServletConfig servletconfig)
        throws ServletException
        super.init(servletconfig);
        context = servletconfig.getServletContext();
        String s;
        if((s = getInitParameter("dir")) == null)
            s = root;
        separator = System.getProperty("file.separator");
        if(!s.endsWith(separator) && !s.endsWith("/"))
            s = s + separator;
        root = s;
    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
        doPost(httpservletrequest, httpservletresponse);
    public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
        Object obj = null;
        String s = "";
        s = HttpUtils.getRequestURL(httpservletrequest).toString();
        int i;
        if((i = s.indexOf("?")) > 0)
            s = s.substring(0, i);
        String s1;
        if((s1 = httpservletrequest.getQueryString()) == null)
            s1 = "";
        else
            s1 = decode(s1);
        if(s1.length() == 0)
            httpservletresponse.setContentType("text/html");
            PrintWriter printwriter = httpservletresponse.getWriter();
            printwriter.println("<html>");
            printwriter.println("<br><br><br>Could not get file name ");
            printwriter.println("</html>");
            printwriter.flush();
            printwriter.close();
            return;
        if(s1.indexOf(".." + separator) >= 0 || s1.indexOf("../") >= 0)
            httpservletresponse.setContentType("text/html");
            PrintWriter printwriter1 = httpservletresponse.getWriter();
            printwriter1.println("<html>");
            printwriter1.println("<br><br><br>Could not use this file name by the security restrictions ");
            printwriter1.println("</html>");
            printwriter1.flush();
            printwriter1.close();
            return;
        File file = lookupFile(root + s1);
        if(file == null)
            httpservletresponse.setContentType("text/html");
            PrintWriter printwriter2 = httpservletresponse.getWriter();
            printwriter2.println("<html>");
            printwriter2.println("<br><br><br>Could not read file " + s1);
            printwriter2.println("</html>");
            printwriter2.flush();
            printwriter2.close();
            return;
        if(!file.exists() || !file.canRead())
            httpservletresponse.setContentType("text/html");
            PrintWriter printwriter3 = httpservletresponse.getWriter();
            printwriter3.println("<html><font face=\"Arial\">");
            printwriter3.println("<br><br><br>Could not read file " + s1);
            printwriter3.print("<br>Reasons are: ");
            if(!file.exists())
                printwriter3.println("file does not exist");
            else
                printwriter3.println("file is not readable at this moment");
            printwriter3.println("</font></html>");
            printwriter3.flush();
            printwriter3.close();
            return;
        String s2 = httpservletrequest.getHeader("Accept-Encoding");
        boolean flag = false;
        if(s2 != null && s2.indexOf("gzip") >= 0 && "true".equalsIgnoreCase(getInitParameter("gzip")))
            flag = true;
        if(flag)
            httpservletresponse.setHeader("Content-Encoding", "gzip");
            httpservletresponse.setHeader("Content-Disposition", "attachment;filename=\"" + s1 + "\"");
            javax.servlet.ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
            GZIPOutputStream gzipoutputstream = new GZIPOutputStream(servletoutputstream);
            dumpFile(root + s1, gzipoutputstream);
            gzipoutputstream.close();
            servletoutputstream.close();
        } else
            httpservletresponse.setContentType("application/octet-stream");
            httpservletresponse.setHeader("Content-Disposition", "attachment;filename=\"" + s1 + "\"");
            javax.servlet.ServletOutputStream servletoutputstream1 = httpservletresponse.getOutputStream();
            dumpFile(root + s1, servletoutputstream1);
            servletoutputstream1.flush();
            servletoutputstream1.close();
    private String getFromQuery(String s, String s1)
        if(s == null)
            return "";
        int i = s.indexOf(s1);
        if(i < 0)
            return "";
        String s2 = s.substring(i + s1.length());
        if((i = s2.indexOf("&")) < 0)
            return s2;
        else
            return s2.substring(0, i);
    private void dumpFile(String s, OutputStream outputstream)
        String s1 = s;
        byte abyte0[] = new byte[4096];
        try
            BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(lookupFile(s1)));
            int i;
            while((i = bufferedinputstream.read(abyte0, 0, 4096)) != -1)
                outputstream.write(abyte0, 0, i);
            bufferedinputstream.close();
        catch(Exception exception) { }
    private String decode(String s)
        StringBuffer stringbuffer = new StringBuffer(0);
        for(int i = 0; i < s.length(); i++)
            char c = s.charAt(i);
            if(c == '+')
                stringbuffer.append(' ');
            else
            if(c == '%')
                char c1 = '\0';
                for(int j = 0; j < 2; j++)
                    c1 *= '\020';
                    c = s.charAt(++i);
                    if(c >= '0' && c <= '9')
                        c1 += c - 48;
                        continue;
                    if((c < 'A' || c > 'F') && (c < 'a' || c > 'f'))
                        break;
                    switch(c)
                    case 65: // 'A'
                    case 97: // 'a'
                        c1 += '\n';
                        break;
                    case 66: // 'B'
                    case 98: // 'b'
                        c1 += '\013';
                        break;
                    case 67: // 'C'
                    case 99: // 'c'
                        c1 += '\f';
                        break;
                    case 68: // 'D'
                    case 100: // 'd'
                        c1 += '\r';
                        break;
                    case 69: // 'E'
                    case 101: // 'e'
                        c1 += '\016';
                        break;
                    case 70: // 'F'
                    case 102: // 'f'
                        c1 += '\017';
                        break;
                stringbuffer.append(c1);
            } else
                stringbuffer.append(c);
        return stringbuffer.toString();
    public String getServletInfo()
        return "A DownloadServlet servlet ";
    private File lookupFile(String s)
        File file = new File(s);
        return file.isAbsolute() ? file : new File(context.getRealPath("/"), s);
    private static final String DIR = "dir";
    private static final String GZIP = "gzip";
    private ServletContext context;
    private String separator;
    private String root;
    private static final String VERSION = "ver. 1.6";
    private static final String CPR = "A DownloadServlet servlet ";
}

Can't be done, for obvious security reasons.
Would you want someone downloading something into your windows\system directory when you navigate to their webpage?

Similar Messages

  • How to get Open/Save Dialogue box

    Hi,
    I need to get open/save dialogue box while downloading a file (from JSP).
    One way which I am currently using is on click of the button pass control to servlet and in servlet using the following code:
    /**.....Some Code */
    response.setContentType("application/csv");
    response.setHeader("Content-Disposition", "attachment; filename=" + filename);
    /**.....Some Code */But I am wondering is there any way I can do the same without passing the control to Servlet? On clicking the button in JSP, is there is any possibilty to get the Open/Save dialogue box directly.
    Thanks
    Arun

    without passing the control to Servlet?Why?
    In HTTP you can send the response only once.The application where i have this requirement is an old one. In the application, I have there are some screens, whose control never goes to Servlet.
    TO be more precise, 2 pages one HTML and another JSP. And the file to be downloaded is created when JSP is called from HTML page. And there is no interaction with Servlet. The JSP inturn calls a method in Java file (which is not a Servlet) and gets all the details including the file to be downloaded.
    I have used window.open() to download the file(in JSP) in order to have Open/Save dialogue box.
    But the approach is working fine in Windows XP systems but not in Windows2000. In Win00 machines it is directly opening the file in popup without giving the user any option for Open/Save.
    Please let me know your suggestion on this.
    Thanks

  • After Downloading v8 I keep getting checking compatibilty dialogue box popping up, then Firfox opens two tabs, Meet Mozilla welcome page and my home page. How can I stop this?

    After Downloading v8 I keep getting checking compatibilty dialogue box popping up when I launch Firefox. Then Firfox opens two tabs, Meet Mozilla welcome page and my home page. How can I stop this?

    That is a legitimate Mozilla newsletter. As it says in the email:
    You're receiving this email because you subscribed to receive email newsletters and information from Mozilla. If you do not wish to receive these newsletters, please click the Unsubscribe link below.
    Unsubscribe https://www.mozilla.org/en-US/newsletter/existing/ad9febcf-65ac-41fd-810b-798945f448f3/
    Modify your preferences https://www.mozilla.org/en-US/newsletter/existing/ad9febcf-65ac-41fd-810b-798945f448f3/ "

  • Bearts Audio Control Pannel will not open. Get error message cannot find startup file

    Bearts Audio Control Pannel will not open. Get error message cannot find startup file!
    Downloaded and instaled up-date for IDT audio from driver up-date. After installation could no longer oppen Beats Audio Control Pannel.  Looked for download to re-install BEATS Audio but cannot find one.
    Any suggestions.
    Sound works with IDT driver installed.
    Pavilion P7-1500Z

    Hi,
    Try using Recovery Manager to reinstall the IDT HD Audio Driver ( this will also reinstall the Beats Audio interface ) - the procedure for using recovery manager to reinstall Software and Drivers is detailed in the document on the link below.
    Recovery Manager - Windows 8.
    Recovery Manager - Windows 7
    After the reinstallation has completed, restart the PC.
    Regards,
    DP-K
    ****Click the White thumb to say thanks****
    ****Please mark Accept As Solution if it solves your problem****
    ****I don't work for HP****
    Microsoft MVP - Windows Experience

  • How  to get  the  Save  dialouge box  in   SAP Business One

    Hi,
    How  to get the  Save dialouge box in    Button  click  event  in  SAP Business One.
    Thanks,
    Y.

    Hello,
    You would like to display an SaveFileDialog box?
    may follow this thread, and you can find a sourcecode in vb.net and c# inside (for open dialog, but it is the similar...)
    Regards
    János

  • Arabic is not listed as a display language in iTunes for Windows 7. How can I add support for this language?

    Arabic is not listed as a display language in iTunes for Windows 7. How can I add support for this language?

    Edit  ---> referance ----->   general    ------> language

  • How can I create a Face Time account.  I have an Apple ID and password.  When I Google how to create an account all I get is what I need for the system

    I have a 13" MacPro.  How can I create a Face Time account.  I have an Apple ID and password.  When I Google how to create an account all I get is what I need for the system

    You don't need to create an account.   Your use your Apple ID to log into Facetime.
    If you haven't already you will need to download the Facetime App from the Mac App Store.
    https://itunes.apple.com/us/app/facetime/id414307850?mt=12&ls=1
    FaceTime for Mac: Troubleshooting FaceTime - Apple Support

  • When I try to install extensions into Dreamweaver CC, I get the following dialogue box in the Extens

    When I try to install extensions into Dreamweaver CC, I get the following dialogue box in the Extension Manager CC:
    "Failed to update database. The extension will not be installed."
    What may the problem be?

    Good day to all,
    The problem that we were having was caused by a case difference between two folders, like Carl pointed out. The line that created the issue was written like this:
    <file source="File1.htm" destination="$dreamweaver/Configuration/Shared/MyExtensions"  />
    <file source="File2.htm" destination="$dreamweaver/Configuration/Shared/myExtensions"  />
    The correct folder was with an upper case ("MyExtensions").
    The extensions are now installing correctly however it seems to take significantly longer to install than on previous versions of EM (even previous version of EM CC). Has anyone been experiencing the same long install time? This only happens on Windows OS. On Mac the extension is installed pretty fast.
    Any idea how I could lower the install time? We do have a long list of files. Maybe try to use only folders instead of individual files?
    Cheers,
    Andrei

  • How do I use my Macbook pro retina display as a monitor for a PC?

    How do I use my Macbook pro retina display as a monitor for a PC?

    MacQueries wrote:
    How do I use my Macbook pro retina display as a monitor for a PC?
    Unfortunately, that is not possible. The computer only can "output" your display image, it cannot "input" an image from an external computer and display it on your MacBook's retina display.

  • I get a repeated dialogue box saying that "Account expired, Renew prescription now to resume service," but nothing as to where this is coming from!

    Every few days I get a small dialogue box saying "Account expired...Renew subscription now to resume service" and there is a Renew Subscription button. There is NOTHING noting what the account is or even the 3 buttons at the top left (Delete, Minimize or Expand). They come up and collect every 3 or 4 days and I have to move them off to the side. The only way to make them disappear altogether is to restart the computer.

    Hello,
    '''Try Firefox Safe Mode''' to see if the problem goes away. Safe Mode is a troubleshooting mode, which disables most add-ons.
    ''(If you're not using it, switch to the Default theme.)''
    * You can open Firefox 4.0+ in Safe Mode by holding the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * Or open the Help menu and click on the '''Restart with Add-ons Disabled...''' menu item while Firefox is running.
    ''Once you get the pop-up, just select "'Start in Safe Mode"''
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshooting extensions and themes]] article for that.
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    You may also have malware, check with all programs.
    * [http://www.microsoft.com/security/scanner/default.aspx Microsoft Safety Scanner]
    * [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware]
    * [http://support.kaspersky.com/faq/?qid=208283363 TDSSKiller - AntiRootkit Utility]
    * [http://www.surfright.nl/en/hitmanpro/ Hitman Pro]
    * [http://www.eset.com/us/online-scanner/ ESET Online Scanner]

  • I keep getting the same dialogue box upon opening Firefox but don't know what to do about it

    I keep getting the same dialogue box upon opening Firefox but don't know what to do about it "Could not initialise the application's security component. The most probable cause is problems with files in your browser's profile directory. Please check that this directory has no read/write restrictions and your hard drive is not full or close to full. It is recommended that you exit the browser and fix the problem. If you continue to use this browser session, you might see incorrect browser behaviour when accessing security features." I have gone to tools - general tab - browse files - but it wont let me browse or set a place to staore files. Any ideas?

    Try the procedures shown in this link - https://support.mozilla.com/kb/Could+not+initialize+the+browser+security+component

  • I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

  • Cannot get the past dialogue box to open in illustrator since upgrading to Yosemite. Click it but nothing happens. Also File Open works intermittently. Is this a finder preference issue?

    Cannot get the past dialogue box to open in illustrator since upgrading to Yosemite. Click it but nothing happens. Also File Open works intermittently. Is this a finder preference issue?

    one of those days --- it's the PLACE dialogue box

  • How come I am not able to get any sound on my playlist

    How come I do not get any sound from mu playlist?

    Maps: Turn-by-Turn Navigation
    Argentina Australia Austria Belgium Brunei Bulgaria Canada Croatia Czech Republic Denmark Egypt Estonia Finland France Germany Greece Hong Kong Hungary Ireland Israel Italy Japan Latvia Liechtenstein Lithuania Luxembourg Macau Malaysia Malta Mexico Morocco Netherlands New Zealand Norway Poland Portugal Romania Russia San Marino Singapore Slovakia Slovenia South Africa South Korea Spain Sweden Switzerland Taiwan Thailand Turkey UK Ukraine USA
    Back to Top

  • Not able to get Out-of-the-Box Examples Index Page for running the jsp examples

    Hi
    I am a new person using weblogic first time I installed the weblogic 7.0 beta
    version on my machine.I am trying to start the weblogic server console so that
    I can configure web applications examples on my machine.
    I am getting following error and not able to view Out-of-the-Box Examples Index
    Page
    error:
    <Apr 5, 2002 12:11:39 PM IST> <Error> <SystemDataStore> <null> <Unable to listen
    on Port 7003: Address in use: JVM_Bind>
    Please help me to find the reason to have this problem
    Thank You in advance
    Vikas

    Hi.
    Please post all WLS 7.0 beta questions to the beta newsgroups -
    weblogic.developer.interest.70beta.*.
    Thanks,
    Michael
    Vikas wrote:
    Hi
    I am a new person using weblogic first time I installed the weblogic 7.0 beta
    version on my machine.I am trying to start the weblogic server console so that
    I can configure web applications examples on my machine.
    I am getting following error and not able to view Out-of-the-Box Examples Index
    Page
    error:
    <Apr 5, 2002 12:11:39 PM IST> <Error> <SystemDataStore> <null> <Unable to listen
    on Port 7003: Address in use: JVM_Bind>
    Please help me to find the reason to have this problem
    Thank You in advance
    Vikas--
    Michael Young
    Developer Relations Engineer
    BEA Support

Maybe you are looking for

  • Ipad 2 doesn't save apple id and password

    Hi all, I bought my parents an ipad2 so that I can use facetime with them.  they are computer illiterate, but they do know how to turn the computer on!  It is becoming very frustrating that their ipad does not automatically hold their ID and password

  • Setup google calendar in calendar

    We have 2 step verification setup on my wife's macbook. Is there some special we need to do in Calendar to get it to sync with google calendar?

  • 3.0 Error: oracle.jdbc.driver.T2CConnection.getLibraryVersionNumber

    Hi, after installing the production version I get this error...., this is not a good start for a production release... :( Any quick and easy solution...? Thanks, Juergen

  • RMI (Internet, LAN, Firewall)

    Hello everybody. In the last view days I solved a lot of problems with my RMI based System... There was the registry problem, the IE problem (no RMI support), the access permission problem and so on... But now everythiung is working properely. I use

  • Panorama photos too small

    Okay,so i have a cool panorama photo,but it's SO small,how would i make it bigger without messing up the quality(say i wanna put it in a long frame on my wall.)I know the video for the apple Itouch5 showed the kids in hallowen costumes and in a frame