Problem in Download Servlet (Urgent)

Hai
i am using an servlet to download files.
i am facing an problem with that servlet.While downloading, at times it strucks at 290k or 330k.
Note : Acually i am calling this servlet from a popup window.The popup window closes automatically after one minute irrescpective of the download progress.At times i noticed that the download strucks while the popup closes, whether is causes the problem of strucking.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Download extends HttpServlet {
HttpSession session =null;
File F;
BufferedInputStream fif;
ServletOutputStream stream;
public void init(){
F=null;
fif=null;
stream =null;
public void doGet(HttpServletRequest request ,HttpServletResponse response) {
try{
     // Setting Buffer size
response.setBufferSize(50000);
               // Setting Content Type
response.setContentType("application/x-filler");
int buffersize;
String cfile="";
boolean flag=false;
session = request.getSession(true);
               //Receiving variables
String fileName= request.getParameter("filename");
String filePath = request.getParameter("filepath");
String downloadFile = filePath + fileName;
F=new File(downloadFile);
String download_date = "sysdate";
String file=F.getName();
buffersize=(int)F.length();
byte b[]=new byte[buffersize];
     //Servet output stream to download file
stream = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename=\"" + file + "\";");
int data;
fif = new BufferedInputStream(new FileInputStream(F));
//writing data to output stream
while((data = fif.read()) != -1) {
stream.write(data);
               //closing objects
fif.close();
stream.close();
F.delete();
}catch(java.net.SocketException se){
System.out.println("SocketException " +se);
catch(IOException io){
System.out.println("IOException " + io);
catch(Exception e){
System.out.println("Exception " +e);      
}

I guess your closing of the window is your problem. Your servlet looks just fine to me.
Try calling this servlet from a browser and see if it still stops..

Similar Messages

  • Problem with a Servlet - URGENT help

    Hello
    i really need your help. here i uploaded my web project: http://www.2shared.com/file/4450238/aaa4d9cd/JMSTest.html
    it's about 2 servlets, one Test servlet sending a message, and another one, Receiver, to receive the message sent via JMS (i use ActiveMQ)
    i didn't know what's wrong, if i call http://localhost:8080/JMSTest , then i enter something into that textfield, then i press the button(form action is http://localhost:8080/test ). it writes that "Mesaj trimis" (message sent - written by me in Romanian), and when i call http://localhost:8080/receiver i did not receive the message. Why?
    I use queue, so i think the send message is stored in a queue until a receiver receives it.
    Please download the project, isn't complicated.
    I did not know what's the problem.
    here is the server.xml file from Tomcat conf folder:
    <?xml version="1.0" encoding="UTF-8"?>
    <Server port="8005" shutdown="SHUTDOWN">
      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
      <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
      </GlobalNamingResources>
      <Service name="Catalina">
        <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>      
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
        <Engine defaultHost="localhost" name="Catalina"> 
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
          <!-- Define the default virtual host
               Note: XML Schema validation will not work with Xerces 2.2.
           -->
          <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
                   prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
            -->
           <Context path="/JMSTest" docBase="JMSTest"
            debug="5" reloadable="true" crossContext="true">
        <Resource name="jms/ConnectionFactory" auth="Container"
                     type="org.apache.activemq.ActiveMQConnectionFactory"
                     description="JMS Connection Factory"
                     factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                     brokerURL="vm://localhost"
                     brokerName="LocalActiveMQBroker"
                     userName="activemq" password="activemq"
                     useEmbeddedBroker="false"
                     clientID="TomcatClientID" />
        <Resource name="jms/myQueue" auth="Container"
                     type="org.apache.activemq.command.ActiveMQQueue"
                     description="JMS Queue"
                     factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                     physicalName="TEST.FOO" />
        <Resource name="jms/myTopic" auth="Container"
                     type="org.apache.activemq.command.ActiveMQTopic"
                     description="JMS Topic"
                     factory="org.apache.activemq.jndi.JNDIReferenceFactory"
                     physicalName="TEST.BAR"/>
    </Context>
           </Host>
        </Engine>
      </Service>
    </Server>or, how should i do this, but using Sun Message Queue? my way is using Apache MQ
    Thanks
    Edited by: Talkabout on Dec 13, 2008 7:15 AM

    I didn't go all through your code, but I'd say you should make sure that the Receiver servlet is up and running BEFORE your access the Sender servlet.

  • Need urgent help on file download servlet problem in Internet Explore

    I have trouble to make my download servlet work in Internet Explore. I have gone through all the previous postings and done some research on the internet, but still can't figure out the solution. <br>
    I have a jsp page called "download.jsp" which contains a URL to download a file from the server, and I wrote a servlet (called DownloadServlet) to look up the corresponding file from the database based on the URL and write the file to the HTTP output to send it back to the browser. <br>
    the URL in download.jsp is coded like <a href="/download/<%= currentDoc.doc_id %>/<%= currentDoc.name %>">on the browser, it will be sth like , the number 87 is my internal unique number for a file, and "myfile.doc" is the real document name. <br>
    in my web.xml, "/download/" is mapped to DownloadServlet <br>
    the downloadServlet.java looks like
    tem_name = ... //read DB for file name
    // set content type
    if ( tmp_name.endsWith(".doc")) {
    response.setContentType("application/msword");
    else if ( tmp_name.endsWith(".pdf")){
    response.setContentType("application/pdf");
    else if ( tmp_name.endsWith(".ppt")){
    response.setContentType("application/vnd.ms-powerpoint");
    else if ( tmp_name.endsWith(".xls")){
    response.setContentType("application/vnd.ms-excel");
    else {
    response.setContentType("application/download");
    // set HTTP header
    response.setHeader("Content-Disposition",
    "attachment; filename=\""+tmp_name+"\"");
    OutputStream os = response.getOutputStream();
    //read local file and write back to browser
    int i;
    while ((i = is.read()) != -1) {
    os.write (i);
    os.flush();
    Everything works fine in Netscape 7.0, when I click on the link, Netscape prompts me to choose "open using Word" or "save this file to disk". That's exactly the behavior I want. <br>
    However in IE 5.50, the behavior is VERY STRANGE.
    First, when I click on the URL, the popup window asks me to "open the file from its current location" or "save the file to disk". It also says "You have chosen to download a file from this location, ...(some url).. from localhost"
    (1) If I choose "save the file to disk", it will save the rendered "download.jsp" (ie, the currect page with URL I just clicked, which isn't what I want).
    (2)But if I choose "open the file from its current location", the 2nd popup window replaces the 1st, which also has the "Open ..." and "Save.." options, but it says "You have chosen to download a file from this location, MYFILE.doc from localhost". (notice it shows the correct file name now)
    (3) If I choose "Save..." on the 2nd window, IE will save the correct file which is "myfile.doc"; if I choose "Open ...", a 3rd replaces the 2nd window, and they look the same, and when I choose "Open..." on the 3rd window, IE will use Word to open it.
    any ideas?
    </a>

    Did you find a solution to this problem? I've been wrestling with the same issues for the past six months. Nothing I try seems to work. I've tried setting the contentLength(), inline vs. attachments, different write algorythms, etc. I don't get the suggestion to rename the servlet to a pdf file.

  • Urgent problem in connecting servlet and oracle

    Hi
    I have problem in connecting servlet with oracle.Kindly let me know what all the classes i should include in classpath to get connected.Where will i find the oracle driver.Kindly help me to do this.
    With regrds
    Vaiju

    http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
    http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/toc.htm
    http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/index.html

  • TS5376 I'm having a problem with downloading and installing the new version of itunes for windows (11.1.4)  I have done everything the troubleshooting article has said and it is still not working properly.

    'm having a problem with downloading and installing the new version of itunes for windows (11.1.4)  I have done everything the troubleshooting article has said and it is still not working properly.  I have even done a repair to see if that works and it has not.  Has anyone else found a new way to get it working?

    Try Troubleshooting issues with iTunes for Windows updates.
    tt2

  • Problem with Download! on N78

    I'm having a problem with Download! on my N78 (sw v. 12.046). I can open Download but it freezes, and I also can't download any applications. When Download! freezes, my only option to shut it down is to boot the phone..I can switch to other open applications but Download! is freezed. This is giving me hard time, can't install any applications. Any help or ideas? Anyone else having this problem?

    Backup your data, and try doing a soft reset. *#7370#, (use this code at your own risk, since it deletes some important data's in your phone memory, including the data of installed applications on phone memory - means if you installed a java file to your card, it stores some data in your phone memory which will be deleted when you soft reset. So you will have to reinstall that software)

  • HT2292 hello i'm facing  problem  i downloaded iTunes version 11 32bit  and after i installing the set up when i opened the iTunes a massages  occur saying i tunes could not connect to iTunes store an unknown error occurred (-3212) even  though my interne

    Hello i'm facing  problem  i downloaded itunes version 11 32bit for windows 7 and after i installing the set up when i opened the iTunes a massages  occur saying i tunes could not connect to iTunes store an unknown error occurred (-3212) even  though my internet is on

    Try this...
    Triple click anywhere in the line below to select it and press Ctrl+C to copy it.
    cmd /k netsh winsock reset
    Press the WinLogoKey+R to open the run dialog, then Ctrl+V to paste, then press enter/return.
    You should get something similar to this:
    Reboot the computer and the problem should be resolved.
    If it doesn't work then perhaps a full tear down and rebuild of iTunes will fix things. See Troubleshooting issues with iTunes for Windows updates for details.
    tt2

  • Problems to Download Dreamweaver CS4 with Akamai Download Manager!

    I want to download Dreamweaver CS4 Italian Windows Trial version.
    I have Internet Explorer 7, PC with OS Windows XP x64bit Corporate, Core2Quad Q9650, Motherboard MSI P45Platinum with Ethernet 10/100/1000,
    4GBRAM,3 HDD 500GB WesternDigital,Nvidia GeForce 9400GT.
    I have installed "Akamai Download Manager ActiveX" control asked on the top of window popup.
    Clicked Yes:Installation confirmation.
    But I have tried to click the button "Download" and just one window with this message appears and disappears immediately:
    Per scaricare il software è necessario installare Akamai Download Manager...
    Problemi di download?
    Assistenza per il download...
    Il sistema non dispone dei requisiti minimi per eseguire Akamai Download Manager.
    (The system doesn't meets the minimum system requirements to run Akamai Download Manager.)
    I can't download anything. Why?
    I have disable Pop-ups Blocker, and disabled also Anti-Phishing Filter.
    Disabled also Antivirus and the Firewall.
    Set and lowered Security Protection from Tools>Internet Options: to "Medium"; and also, another time, set to "Personalized" with all the controls
    switched to "Active".
    Set Privacy>Settings>"Accetta tutti i cookie"(lowered to full bottom).
    I have read this Akamai Download Manager FAQ:
    -"Nothing happens when I click the download link"
    If nothing happened after you clicked the download link, either your pop-up blocker or a high security setting on your web browser may have stopped
    the Akamai DLM window from opening.
    If you have a pop-up blocker enabled in your web browser or in your Internet toolbar (such as the Yahoo! toolbar or the Google toolbar), you will
    need to disable your pop-up blocker to start your download. For additional information, and for instructions on changing your security setting, see
    the "Akamai Download Manager system requirements" (ServiceNote kb400530).
    Note: The download manager can sometimes take up to a minute to load. Please allow time for the initial loading before assuming there is a problem
    Thus, I have followed this rules in Akamai Download Manager System Requirements:
    Internet Explorer 7
    1) Access your Internet options from the Windows Control Panel (Internet Options) or by selecting Tools > Internet Options in Internet Explorer
    2) Select the Security Tab
    3) Click Custom Level
    4) Scroll through the list of security options and set:
    -ActiveX controls and plug-ins > Download signed ActiveX controls > Enable or Prompt
    -ActiveX controls and plug-ins > Run ActiveX controls and plug-ins > Enable or Prompt
    -ActiveX controls and plug-ins > Script ActiveX controls marked safe for scripting > Enable or Prompt
    -Downloads > File download > Enable
    -Miscellaneous > Allow script-initiated windows without size or position constraints > Enable
    -Scripting > Active scripting > Enable
    5) Click OK
    6) Click OK again
    But nothing changes.
    On my PC I have also this installation: "J2SE Runtime Environment 5.0 Update 5" and "Java(TM)6 Update 15".
    But the download doesn't start at all.
    1) How can I do to download Dreamweaver CS4-Windows-ITALIAN language?
    2) Is it possible to download 364.8 MegaBytes without Akamai Download Manager?
    Please Hurry!
    Horsepower0171.

    another option you may have is resettofactory
    start- run- type:
    cmd
    press enter
    type:
    cd c:\program files\common files\research in motion\apploader
    press enter
    type:
    loader.exe /resettofactory
    press enter
    please perform a backup first
    test your browser before you restore your backup, and to be ssafe I would do a selective restore
    open DTM, go to backup/restore- advanced
    top left click on file-open
    find your backup, it will load on the left side
    you current working BB will be on the right side
    transfer ONLY the absolute important databases from the left to the right(address, cal, phone logs, messages, sms, tasks, memo)... dont do any that you dont know and dont do any OPTIONS ones
    Message Edited by drizzt09 on 07-13-2009 08:40 PM

  • HT1222 I am trying to update my phone so I can save my info on my old phone & get a new phone, but I get a error that says "There was a problem with downloading teh software, the network connection timed out.."  HELP!  Not sure what my settings shoud be..

    I am trying to update my phone so I can save my info on my old phone & get a new phone, but I get a error that says "There was a problem with downloading teh software, the network connection timed out.."  HELP!  Not sure what my settings shoud be...
    I never updated anything until now...I want o update my iPhone to the newest version, but i do not want ot loose all that I have on this phone. I was told I needed to update the operating systems so i can put things into the cloud for transport to new phone, but I am just not sure how to do this..Can you help out here??

    Dear Jody..jone5
    Good for you that can't update your iphone because I did it and my iphone dosen't work for example I can't download any app like Wecaht or Twitter..
    Goodluck
    Atousa

  • I am facing the problem on downloading apps from Mac App Store, when I try to install the application from App store, I am getting an error message "Status_Code_Error" while click on "Login"

    I am facing the problem on downloading apps from Mac App Store, when I try to install the application from App store, I am getting an error message "Status_Code_Error" while click on "Login"

    Same problem here in Brazil.
    It seems to be a problem with logging in App Store in the Mac (Yosemite 10.10.2).
    When I tried the very same userid and password I was able to login in to use my iCloud account from the same computer and also from my iPhone.

  • Windows 8.1 account limit problem when downloading from store

    windows 8.1 account limit problem when downloading from store        
    I have 250 windows 8.1 tablets.
    I figured since you can use the same account on 81 devices id create 4 accounts.
    I need to download more than 25 free apps from the store
    on each tablet. Putting the same account don't work. (comes up with an error after putting on to many devices that you cant use this account now).
    Whats the best way to do this ? and what if I need to download a paid app ?
    Thank You.

    Hi,
    As far as I know, One Microsoft Account may bound at most five Trusted computers. There is no way to break this limitation.
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Japanese character problem while downloading file to application server

    Hello All,
    We are facing a strange problem while downloading a file to application server when file contains japanese text.
    We are downloading vendor and customer information in a flat file format on application server. When the login language is EN program show ouput in a properly formatted manner.
    When the login language is JA (japanese) program does download file with customer vendor data. I can see the description is japanese language but the formatting is gone for a toss.
    We are facing similar issue with other programs downloading files on the application server.
    I am using OPEN DATASET........ENCODING DEFAULT. and working on unicode enabaled ECC 6.0 system
    Quick help appriciated.
    Thanks!

    Hi
    Sometimes this also happens because of your desktop setting.Make sure that your OS also supports the JAPANESSE language.
    Ask your technical support team to enable them in your desktop.
    Thanks & Regards
    Jyo

  • Getting  save as dialog while downloading using download servlet

    Hi Folks,
    I am developing a web based video download application.In this i intend to download the video file by calling a download servlet.
    Though the application works ,that is it downloads the file, the video file is straight away being played by the media player.My objective is to save it in the client machine at the desired location of the hard disk and then play the same later at cient's convenience. This is not happenening with my application.
    Pl suggest me as how to get the save as dialog box to save the video file at will.
    The site is to be lauched in a weeks time.Pl help!!!
    thanks and regards
    sathiyam K G

    Hi rupak,
    Thanks for the tip.I actually did all the things u said.But the difference is that i rely on http download.
    I mean i do not use the servlet output stream to download the video file.If i do so it takes about 20 mins for a 10 MB sample file,to be downloaded via a broad band T1 link.
    So i just use href to depend on http by which the download speed is accelerated and my one clip of video of 100MB average size can be downloaded in about 15 min. duration.
    If this is not the correct way of working for the video download will u pl suggest me any other way through servlet, i can download with the above specified speed.
    i am clear if i use the servlet output stream the download process is deadly slow.
    so pl suggest!!
    thanks again
    regards
    sathiyam K G

  • Re: Problem providing download link for BLOB data in apex report

    Hi Don,
    Your solution below worked but in the download option i only see save but not open for PDf file in the blob. Please let me know if you have any suggestion to achieve it
    Thanks
    Jo
    Problem providing download link for BLOB data in apex report 
    591953 Nov 19, 2008 1:55 PM (in response to 660436)
    Currently Being Moderated
    Good morning,
    Here is how I have solved this problem.
    1. The select statement in the sql for the report should not include the BLOB column. I decided to select only 2 columns, the column that has the key and the column with the filename.
    2. On the first column ( the primary key ) I put in the format statement that was simply DOWNLOAD:TABLENAME:BLOB_COLUMN:PRIMARY_KEY
    This works. I believe that the Oracle error I was getting was because I was trying to apply this format statement to the actual BLOB column.
    So, it appears that you can use any of the columns in the report to hold the DOWNLOAD format statement since in the format statement, you are defining the BLOB table, BLOB column and the primary key into that column.
    Hope this helps,
    Don.

    Branched out from a years old thread.
    user3003326 Don't post to old threads, please.

  • I have a problem for download in app store . it shows error code : 1009

    i have a problem for download in app store . it shows error code : 1009

    https://discussions.apple.com/thread/2439043

Maybe you are looking for