?
Solved

Links in JSP page not working after calling Download Servlet...

Posted on 2003-03-14
21
Medium Priority
?
538 Views
Last Modified: 2008-01-16
Hi,

I am using a Download Servlet to download a csv file in the JSP Page. After a successful download, the other links on the page are ignored by the browser (IE 6).
I have used the following code in the Download servlet...
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","application; filename=\"csvfile.csv\"");

What could be the problem? Any workarounds for this? I want to download the file and I don't want to open the file in the browser by giving "inline" instead of "application".

Thanks,
Shashi
0
Comment
Question by:nsbhushan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 4
  • 2
  • +2
21 Comments
 
LVL 3

Accepted Solution

by:
paskal earned 400 total points
ID: 8135630
I  think you have to leave out the setContentType. And instead of 'application' as content-disposition I have 'attachment' and it works fine for me.
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 400 total points
ID: 8136064
 Can you also try to set the content type to:

  setContentType("application/unknow");

  and see what happens?
0
 
LVL 14

Assisted Solution

by:kennethxu
kennethxu earned 400 total points
ID: 8136427
agree with paskal and girionis. you need both:
response.setContentType("application/unknow");
response.setHeader("Content-Disposition","attachment; filename=\"csvfile.csv\"");

grand points to paskal and girionis if your problem is solved.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:nsbhushan
ID: 8136930
I tried with
response.setContentType("application/unknow");
response.setHeader("Content-Disposition","attachment; filename=\"csvfile.csv\"");

It didn't work out. File is downloaded successfully but the links in the JSP page are still ignored. :-(
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8137046
how do you place the link on page, try <a target="_new" href="csvservlet"> click to download </a>
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 8139801
is there a url to the page we can test it with?
0
 

Author Comment

by:nsbhushan
ID: 8141677
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 

Author Comment

by:nsbhushan
ID: 8141766
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 

Author Comment

by:nsbhushan
ID: 8141777
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 

Author Comment

by:nsbhushan
ID: 8141817
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 

Author Comment

by:nsbhushan
ID: 8141884
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 

Author Comment

by:nsbhushan
ID: 8141892
I am calling the Servlet in many pages. In some pages I call it through a hyperlink and In some cases I have to call the servlet using jsp response.sendRedirect().

I tried with target="_new". It works, but opens up a new window. I tried using window.open() and closing the window on Load event of the window. It works fine in case of a link.  But, in case of sendRedirect(), links say no no! :-(

The pages are being tested in the intranet yet and I am afraid I am not able to give a url to the page. :-(

Any chance??!
0
 
LVL 92

Expert Comment

by:objects
ID: 8144664
> the other links on the page are ignored by the browser (IE 6).

What exactly do u mean by 'ignored'?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8144944
hmm, it looks like IE bug. Did you test it on other PC's IE or netscape?

have a look at this: http://support.microsoft.com/default.aspx?scid=kb;EN-GB;q281679
0
 

Author Comment

by:nsbhushan
ID: 8150739
I meant the link is not working. I am suppose to be redirected to another page on click of a specific link. But, on clicking the link, I am still in the same page.

And, yes. it is specific to IE. There is no problem in Netscape.

I tried with the link suggested by kennethxu. No luck. Moreover, I can not tell the clients to do all that updations to IE. :-(

Any other workaround?!

My download servlet code looks like this

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DownloadServlet extends HttpServlet{

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{
        doPost(request,response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{

        HttpSession session = request.getSession();

        String dispFile = (String)session.getAttribute("DOWNLOAD_FILE");
        String realFile = (String)session.getAttribute("DOWNLOAD_PATH");

        if(realFile == null || realFile.trim().equals(""))
            return;

        File file = null;
        String ofname = "";
        FileInputStream fis = null;

        try {
            file = new File(realFile);
            ofname = dispFile;
            ofname = new String(ofname.getBytes("Shift_JIS"), "ISO8859_1");
            fis = new FileInputStream(file);
        } catch(Exception e) {
            return;
        }

        int data;
        response.setContentType("application/unknow");
        response.setHeader("Content-Disposition","attachment; filename=\"" + ofname + "\"");
        response.setContentLength((int)file.length());

        BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
        try {
            while( (data = fis.read()) != -1){
                out.write(data);
            }
        } catch (Exception e) {
               System.out.println(e.toString());
        } finally {
               if(out != null)
                out.close();
        }
    }
}


- Shashi.
0
 

Author Comment

by:nsbhushan
ID: 8150778
I meant the link is not working. I am suppose to be redirected to another page on click of a specific link. But, on clicking the link, I am still in the same page.

And, yes. it is specific to IE. There is no problem in Netscape.

I tried with the link suggested by kennethxu. No luck. Moreover, I can not tell the clients to do all that updations to IE. :-(

Any other workaround?!

My download servlet code looks like this

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DownloadServlet extends HttpServlet{

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{
        doPost(request,response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{

        HttpSession session = request.getSession();

        String dispFile = (String)session.getAttribute("DOWNLOAD_FILE");
        String realFile = (String)session.getAttribute("DOWNLOAD_PATH");

        if(realFile == null || realFile.trim().equals(""))
            return;

        File file = null;
        String ofname = "";
        FileInputStream fis = null;

        try {
            file = new File(realFile);
            ofname = dispFile;
            ofname = new String(ofname.getBytes("Shift_JIS"), "ISO8859_1");
            fis = new FileInputStream(file);
        } catch(Exception e) {
            return;
        }

        int data;
        response.setContentType("application/unknow");
        response.setHeader("Content-Disposition","attachment; filename=\"" + ofname + "\"");
        response.setContentLength((int)file.length());

        BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
        try {
            while( (data = fis.read()) != -1){
                out.write(data);
            }
        } catch (Exception e) {
               System.out.println(e.toString());
        } finally {
               if(out != null)
                out.close();
        }
    }
}


- Shashi.
0
 

Author Comment

by:nsbhushan
ID: 8150858
I meant the link is not working. I am suppose to be redirected to another page on click of a specific link. But, on clicking the link, I am still in the same page.

And, yes. it is specific to IE. There is no problem in Netscape.

I tried with the link suggested by kennethxu. No luck. Moreover, I can not tell the clients to do all that updations to IE. :-(

Any other workaround?!

My download servlet code looks like this

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DownloadServlet extends HttpServlet{

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{
        doPost(request,response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{

        HttpSession session = request.getSession();

        String dispFile = (String)session.getAttribute("DOWNLOAD_FILE");
        String realFile = (String)session.getAttribute("DOWNLOAD_PATH");

        if(realFile == null || realFile.trim().equals(""))
            return;

        File file = null;
        String ofname = "";
        FileInputStream fis = null;

        try {
            file = new File(realFile);
            ofname = dispFile;
            ofname = new String(ofname.getBytes("Shift_JIS"), "ISO8859_1");
            fis = new FileInputStream(file);
        } catch(Exception e) {
            return;
        }

        int data;
        response.setContentType("application/unknow");
        response.setHeader("Content-Disposition","attachment; filename=\"" + ofname + "\"");
        response.setContentLength((int)file.length());

        BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
        try {
            while( (data = fis.read()) != -1){
                out.write(data);
            }
        } catch (Exception e) {
               System.out.println(e.toString());
        } finally {
               if(out != null)
                out.close();
        }
    }
}


- Shashi.
0
 

Author Comment

by:nsbhushan
ID: 8150866
My comment is getting posted again and again if I refresh the page!
Bug?!
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8151976
>> I tried with the link suggested by kennethxu. No luck. Moreover, I can not tell the clients to do all that updations to IE. :-(

Just one PC, or IE on all PCs? you servlet looks fine, that's IE's bug, even with the latest update, sometime must do a re-install to solve this problem.

BTW, i don't see anything wrong in your servlet.

>> My comment is getting posted again and again if I refresh the page!
that's EE bug. use the reload link on upper-left of the page, and then refresh.
0
 
LVL 35

Expert Comment

by:girionis
ID: 10041161
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between paskal, girionis, kennethxu and objects

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question