日期:2014-05-20  浏览次数:20887 次

jsp里点击按钮出现一个对话框,让用户选择文件保存路径怎么写?
jsp里点击按钮出现一个对话框,让用户选择文件保存路径,然后后台的java获取到路径,按路径保存,后台的我会写,但是前台不知道怎么弄,谁会给我讲讲啊,怎么样一点击按钮就会弹出那个对话框呢?

------解决方案--------------------
文件下载,在jsp页面加一段java代码,给你贴个例子:
jsp页面加上这段代码的话、就会弹出框框 提示你打开还是保存?
java.text.SimpleDateFormat tempDate = new java.text.SimpleDateFormat(
"yyyyMMddHHmmss");
String time = tempDate.format(new Date());
String fileName = "用户基本信息_" + time + ".doc";
fileName = new String(fileName.getBytes("GBK"), "ISO8859_1");
response.setHeader("Content-Disposition", "attachment;filename="
+ fileName);

response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
------解决方案--------------------
jsp页面
<a href="xxxAction.do?fileId=...">点击下载</a>

struts.xml
<action name="xxxAction" class="downAction">
<result name="success" type="stream" >
<param name="fileName" >file</param>
<param name="contentDisposition" >attachment;filename=${filename}</param>
<param name="buffersize">1024</param>
</result>
downAction
private String filename;
private InputStream file;
private String fileId;
public String execute(){
ServletContext sc=ServletActionContext.getServletContext();
String path=sc.getRealPath("upload");
filename=""+fileId;
file=new FileInputStream(path+File.separator+filename);
return "success";
 
}

------解决方案--------------------
看你jsp 页面charset是什么。。..