六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 335|回复: 0

struts2文件下载

[复制链接]

升级  25.33%

22

主题

22

主题

22

主题

秀才

Rank: 2

积分
88
 楼主| 发表于 2013-2-8 01:03:40 | 显示全部楼层 |阅读模式
下面是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>

您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表