Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • Last Modified:

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

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
nsbhushan
Asked:
nsbhushan
  • 11
  • 4
  • 2
  • +2
4 Solutions
 
paskalCommented:
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
 
girionisCommented:
 Can you also try to set the content type to:

  setContentType("application/unknow");

  and see what happens?
0
 
kennethxuCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
nsbhushanAuthor Commented:
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
 
kennethxuCommented:
how do you place the link on page, try <a target="_new" href="csvservlet"> click to download </a>
0
 
objectsCommented:
is there a url to the page we can test it with?
0
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
objectsCommented:
> the other links on the page are ignored by the browser (IE 6).

What exactly do u mean by 'ignored'?
0
 
kennethxuCommented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
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
 
nsbhushanAuthor Commented:
My comment is getting posted again and again if I refresh the page!
Bug?!
0
 
kennethxuCommented:
>> 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
 
girionisCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 11
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now