0

I want to invoke my jsp page from my index.html.This is html code.

 <html>
            <head>
                <title></title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            </head>
            <form action="DownloadFile.jsp">
                <body>
                     <div>Click here Download File from Server...</div>
                     <input type="submit" name="downloadButton" value="Download..." />
                </body>
            </form>
    </html>

JSP PAGE:

    <%

                    String filename = "Sample1.zip"; 
                    String filepath = "e:\\temp\\"; 
                    response.setContentType("APPLICATION/OCTET-STREAM"); 
                    response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\""); 

                    java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath + filename);

                    int i; 
                    while ((i=fileInputStream.read()) != -1) {
                    out.write(i); 
                    } 
                    fileInputStream.close();
            %>

But When i pressing Download Button, it just shows the jsp file content as html.it does not start downloading the file anyway. What is the problem here...

and also i cann't download .docx and .jpg files correctly.It says file may be corrupted...

Please Guide me to get out of this both issues...

Is there a common way to download all types of files in jsp?

Saravanan
  • 11,372
  • 43
  • 143
  • 213
  • As to *"Is there a common way to download all types of files in jsp?"*, head to http://stackoverflow.com/q/1812244 – BalusC Oct 07 '15 at 15:29

3 Answers3

1

Your server either does not support JSP or is not configured for it.

You need a JSP capable server.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • i am using netbeans7 and tomcat 7.But i can able to run jsp file by directly put the path in browser... – Saravanan May 22 '12 at 11:11
1

Have you configured the Servlet engine with you webserver and done the setup for forwarding request for jsp files to server engine.

ejb_guy
  • 1,125
  • 6
  • 6
-1

Actually, you do not need jsp to download you content . Instead, if you want to download from the client end, you can use html5

 <!DOCTYPE html>
<html>
<body>

<p>Click on the below hyperlink to download the any such file:<p>

<a href="5.csv" download>
test
</a>