CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   error while trying to download Excel file using java (http://www.codingforums.com/showthread.php?t=282522)

naveendk.55 11-18-2012 10:49 PM

error while trying to download Excel file using java
 
I am trying to download excel file from server after clicking on a link. I have written the below JSP and Servlet code. JSP and Servlet are both in the same folder. I get the error "The requested resource (/BulkAccess/Download) is not available" after clicking on hyperlink to download the excel file. Any help?

JSP CODE
Code:


 <body>

  <a href="Download"> Sample Excel File </a>

  </body>


SERVLET

Code:

  import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

@SuppressWarnings("serial")
public class Download extends HttpServlet {
    public void doGet(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException {

        String filename = "C:\\excelFile.xls";


        ServletOutputStream out = response.getOutputStream();
        FileInputStream in = new FileInputStream(filename);

        response.setContentType("application/vnd.ms-excel");
        response.addHeader("content-disposition",
                "attachment; filename=" + filename);

        int octet;
        while((octet = in.read()) != -1)
            out.write(octet);

        in.close();
        out.close();
    }

    public void doPost(HttpServletRequest request,HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
Servlet mapping in xml file

<servlet>
<servlet-name>Download</servlet-name>
<servlet-class>com.abc.bulk.Download</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Download</servlet-name>
<url-pattern>/Download</url-pattern>
</servlet-mapping>


All times are GMT +1. The time now is 03:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.