• 手动搭建HTTP下载站点


    手动搭建HTTP下载站点

    index.jsp

    <%--Listfile.jsp--%>
    <%@ page import="java.io.File,java.text.SimpleDateFormat,java.util.Calendar"%>
    <%@ page contentType="text/html;charset=GB2312" language="java" %>
    <html>
    <head>
    <title>index</title>
    <style type="text/css">
    body {
        font-size: 9pt;
        background-color: #F0F0F0;
    }
    TABLE {
        background-color: #CCCCCC;
        font-size: 9pt;
    }
    TR {
        color: black;
        height: 22px;
        background-color: white
    }
    TR.header {
        color: #996600;
        height: 22px;
        background-color: #EBEBEB;
        cursor: hand
    }
    </style>
    </head>
    <body>
    <%!
        public void travelDirectory(String directory, JspWriter out) {
            try {
                File dir = new File(directory);
                if (dir.isFile()) // 判断是否是文件,如果是文件则返回。
                    return;
                File[] files = dir.listFiles(); // 列出当前目录下的所有文件和目录
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isDirectory()) {
                        continue;
                    } // 如果是目录,则继续遍历该目录
                    // travelDirectory(files[i].getAbsolutePath(),out);
                    if(files[i].getName().equals("index.jsp")){
                        continue;
                    }
                    String fn = files[i].getName();
                    String fs = files[i].length()/(1024 * 1024) + "M";
                    Calendar cal = Calendar.getInstance();
                    long time = files[i].lastModified();
                    SimpleDateFormat formatter = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss");
                    cal.setTimeInMillis(time);
                    String ft = formatter.format(cal.getTime());
                    String tr = "<tr><td><a href='" + fn + "' target='_blank'>" + fn + "</a></td>";
                    tr += "<td>" + fs + "</td>";
                    tr += "<td>" + ft + "</td></tr>";
                    out.println(tr); // 输出该目录或者文件的名字
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    %>
    <%
        //将当前web程序目录结构输出到控制台
        String path=pageContext.getServletContext().getRealPath(request.getServletPath());
        String dir=new File(path).getParent(); 
        out.println("<div align='center'>软件下载界面,点击文件名称下载</div><table align='center'>");
        out.println("<tr class='header'><td>文件名称</td><td>大小(M)</td><td>修改时间</td></tr>");
        travelDirectory(dir,out);
        out.println("</table>");
    %>
    </body>
    </html>

    web.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
        PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>Welcome to download</display-name>
        <description>
            Welcome to download
        </description>
        <mime-mapping>
            <extension>zip</extension>
            <mime-type>application/zip</mime-type>
        </mime-mapping>
        <mime-mapping>
            <extension>rar</extension>
            <mime-type>application/rar</mime-type>
        </mime-mapping>
        <mime-mapping>
            <extension>exe</extension>
            <mime-type>application/octet-stream</mime-type>
        </mime-mapping>
        <mime-mapping>
            <extension>iso</extension>
            <mime-type>application/octet-stream</mime-type>
        </mime-mapping>
        <mime-mapping>
            <extension>docx</extension>
            <mime-type>application/doc</mime-type>
        </mime-mapping>
        <mime-mapping>
            <extension>doc</extension>
            <mime-type>application/doc</mime-type>
        </mime-mapping>
    </web-app>
  • 相关阅读:
    2017-2018-1 20179226 《文献管理与信息分析》第1讲学习总结
    2017-2018-1 20179226《Linux内核原理与分析》第十一周作业
    2017-2018-1 20179226《Linux内核原理与分析》第十周作业
    2017-2018-1 20179226 《从问题到程序》第2周学习总结
    2017-2018-1 20179226 《构建之法》第1周学习总结
    掌握一种编辑器-Vim
    2017-2018-1 20179226 《深入理解计算机系统》第1周学习总结
    2017-2018-1 20179209《Linux内核原理与分析》第二周作业
    20179209《Linux内核原理与分析》第一周作业
    linux_cpu信息查询
  • 原文地址:https://www.cnblogs.com/stono/p/8375737.html
Copyright © 2020-2023  润新知