|
|
下面是jsp文件的代码:
<div class="highlighter">
- <%@pagelanguage="java"import="java.io.*"pageEncoding="GBK"%>
- <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
- <html>
- <head>
- <title>MyJSP'down.jsp'startingpage</title>
- <metahttp-equiv="pragma"content="no-cache">
- <metahttp-equiv="cache-control"content="no-cache">
- <metahttp-equiv="expires"content="0">
- <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
- <metahttp-equiv="description"content="Thisismypage">
- <!--
- <linkrel="stylesheet"type="text/css"href="styles.css">
- -->
- </head>
- <body>
- <%
- //取得服务器"/download"目录的物理路径
- Stringpath=request.getRealPath("/download");
- //取得"/download/file"目录的file对象
- Filefile=newFile(path);
- //取得file目录下所有文件
- File[]files=file.listFiles();
- for(inti=0;i<files.length;i++){
- Stringfname=files.getName();
- //对文件名进行url编码(UTF-8指明fname原来的编码,UTF-8一般由本地编码GBK代替)
- fname=java.net.URLEncoder.encode(fname,"UTF-8");
- out.println("<ahref=download.action?name="+fname+">"
- +files.getName()+"</a><br>");
- }
- %>
- </body>
- </html>
|
|