简体   繁体   English

如何从我的index.html文件调用jsp页面?

[英]how to invoke jsp page from my index.html file?

I want to invoke my jsp page from my index.html.This is html code. 我想从index.html调用我的jsp页面。这是html代码。

 <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. 但是当我按下Download Button时,它只是将jsp文件内容显示为html.it仍然不会开始下载文件。 What is the problem here... 这里有什么问题...

and also i cann't download .docx and .jpg files correctly.It says file may be corrupted... 而且我无法正确下载.docx和.jpg文件。它说文件可能已损坏...

Please Guide me to get out of this both issues... 请指导我摆脱这两个问题...

Is there a common way to download all types of files in jsp? 有没有一种通用的方法可以在jsp中下载所有类型的文件?

Your server either does not support JSP or is not configured for it. 您的服务器不支持JSP或未为其配置。

You need a JSP capable server. 您需要一个支持JSP的服务器。

您是否已与Web服务器一起配置了Servlet引擎,并完成了将jsp文件请求转发到服务器引擎的设置。

Actually, you do not need jsp to download you content . 实际上,您不需要jsp即可下载content。 Instead, if you want to download from the client end, you can use html5 相反,如果要从客户端下载,可以使用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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从JSP页面返回index.html(登录页面)? - How can I go back from a JSP page to index.html (the login page) ? 如何将 Java jsp Arrays 设置到我的 Index.html 表 - How to Set Java jsp Arrays to my Index.html Table 如何在webapp中查看我的index.html文件,该文件是从url上的swagger ui克隆的 - how to view my index.html file inside webapp which is cloned from swagger ui on a url 如何通过index.html spring更改index.jsp - how to change index.jsp by index.html spring 在Jboss服务器中如何配置页面index.html从机器ip而不是localhost调用 - In Jboss server how to configure page index.html to be called from machine ip instead of localhost 如何创建从Netbeans中的Java servlet到index.html或其他页面的链接? - How Do i create a link from a Java servlet in Netbeans back to a index.html or another page? 如何将站点的主页重定向到/public/index.html路径 - How to redirect the home page of the site to /public/index.html path index.html被忽略还是默认servlet优先于index.jsp和index.html? 为什么? - index.html ignored or default servlet got priority over index.jsp and index.html? Why? 如何在该本地主机中打开资源:8080 / test / index.html? - How to open my resource in that localhost:8080/test/index.html? 本地主机时如何重定向到本地存储的 index.html 文件:<port> 从浏览器调用</port> - How to redirect to locally stored index.html file when localhost:<port> is called from a browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM