社区
Web 开发
帖子详情
请教:如何在JSP中保存一个文件到指定的路径里(打开保存文件对话框):等待,另开贴给分!
kw123
2004-09-08 10:05:09
得到一串数byte类型,写入指定文件(保存文件对话框所指定的文件);
如何实现?
另开贴散分!
...全文
610
16
打赏
收藏
请教:如何在JSP中保存一个文件到指定的路径里(打开保存文件对话框):等待,另开贴给分!
得到一串数byte类型,写入指定文件(保存文件对话框所指定的文件); 如何实现? 另开贴散分!
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zxf9720
2004-10-06
打赏
举报
回复
不好意思,回错贴了
zxf9720
2004-10-06
打赏
举报
回复
搞定了,换了种方式,呵呵,谢谢各位! :)
kw123
2004-09-14
打赏
举报
回复
没有下文!!
kw123
2004-09-10
打赏
举报
回复
FileDialog fileDialog=new FileDialog(m_Frame,"另存什么文件?");//此处 m_Frame的详细些
fileDialog.setFile("*.doc");
fileDialog.setDirectory(".");
fileDialog.show();
String strSaveFile;
if((strSaveFile=fileDialog.getFile())!=null)
{
m_FileName.setText(strSaveFile);
m_Directory.setText(fileDialog.getDirectory());
}
else
{
m_FileName.setText("取消");
m_Directory.setText("");
}
kw123
2004-09-09
打赏
举报
回复
:to
gjd111686(数字金刚)
m_Frame??
chancelin
2004-09-09
打赏
举报
回复
byte[] b=new byte[4096]; //要输出的字节流
String outFileName = "filename";// 默认的文件名字和路径
response.setContentType("application/octet-stream");// 设置响应头
response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");//提示IE保存文件,弹出保存文件对话框
java.io.OutputStream pw = response.getOutputStream();
pw.write(b,0,b.length); //输出字节流
pw.close();
vampirewp
2004-09-09
打赏
举报
回复
试试这个,用一个单独的JSP页面来作处理,传文件名和路径过来
<%
// 得到文件名字和路径
String fileName = "HousePrice.xls";
String filePath = "";
if(request.getParameter("fileName")!=null){
fileName = request.getParameter("fileName");
}
if(request.getParameter("filePath")!=null){
filePath = request.getParameter("filePath");
}
String realPath = request.getRealPath("");
filePath = realPath + filePath;
System.out.println("fileName is:"+fileName);
System.out.println("filePath is:"+filePath);
// 设置响应头和下载保存的文件名
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();
out.close();
%>//这后面一定不能再有换行符,不然编译会报错
gjd111686
2004-09-09
打赏
举报
回复
是这个意思吗?
FileDialog fileDialog=new FileDialog(m_Frame,"另存什么文件?");
fileDialog.setFile("*.doc");
fileDialog.setDirectory(".");
fileDialog.show();
String strSaveFile;
if((strSaveFile=fileDialog.getFile())!=null)
{
m_FileName.setText(strSaveFile);
m_Directory.setText(fileDialog.getDirectory());
}
else
{
m_FileName.setText("取消");
m_Directory.setText("");
}
kw123
2004-09-09
打赏
举报
回复
我指定一个路径和文件名称是可以将其保存的!
现在目的就像我们常用的另存为的对话框那样指定sPathFujian+"/"+sFile
开始我想我FILEDIALOG实现,但一直没有办法!你们有何高招???
SaveFileAs(sFj,sPathFujian+"/"+sFile);
public void SaveFileAs(String sFj,String filename){
try
{
// FileDialog fd =new FileDialog(this,"SaveFile",FileDialog.SAVE);
// fd.show();
// String filename = fd.getDirectory() + fd.getFile();
File file1 = new File(filename);
FileOutputStream myFileoutputstream = new FileOutputStream(file1);
byte[] buffer ;
buffer= sFj.getBytes();
int chunk = buffer.length;
myFileoutputstream.write(buffer, 0, chunk);
myFileoutputstream.close();
}
catch(Exception e){
}
}
gjd111686
2004-09-09
打赏
举报
回复
m_Frame是JFrame对象的实例.
gjd111686
2004-09-09
打赏
举报
回复
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" valign="top">测试XMLHTTP</td>
</tr>
</table>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" valign="top">
<input type="text" value="http://10.70.38.10:9002/System/Dot/Show.jsp?Id=1" id="URLID">
<input type="text" value="C:\\DownURL.doc" id="LocalURLID">
<input type="button" value="下载" onclick="DownURL(URLID.value,LocalURLID.value);">
</td>
</tr>
</table>
<br>
<div id=App style="border:1 solid #000000;background-color:#FFFFFF;height:200px;overflow:auto;width:80%;z-index:2" contentEditable></div>
<script>
function OpenFile(strFileName)
{
try
{
var WordApp=new ActiveXObject("Word.Application");
WordApp.Application.Visible=false;
var Doc=WordApp.Documents.Open(strFileName);
Doc.Activate();
Doc.Parent.Options.InsertedTextColor=4;
Doc.Parent.Options.InsertedTextMark=2;
Doc.Parent.Options.DeletedTextColor=4;
Doc.Parent.Options.DeletedTextMark=1;
Doc.TrackRevisions=true;
Doc.PrintRevisions=true;
Doc.ShowRevisions=true;
Doc.Application.UserName="";
var Range=Doc.Range();
Range.Select();
var Selection=WordApp.Selection;
Selection.Copy();
App.focus();
document.execCommand("Paste");
App.focus();
WordApp.DisplayAlerts=false;
Doc.Close();
WordApp.DisplayAlerts=true;
WordApp.Quit();
}
catch(e)
{
window.confirm(e);
}
}
function DownURL(strRemoteURL,strLocalURL)
{
try
{
var xmlHTTP=new ActiveXObject("Microsoft.XMLHTTP");
xmlHTTP.open("Get",strRemoteURL,false);
xmlHTTP.send();
var adodbStream=new ActiveXObject("ADODB.Stream");
adodbStream.Type=1;//1=adTypeBinary
adodbStream.Open();
adodbStream.write(xmlHTTP.responseBody);
adodbStream.SaveToFile(strLocalURL,2);
adodbStream.Close();
adodbStream=null;
xmlHTTP=null;
OpenFile(strLocalURL);
}
catch(e)
{
window.confirm("下载URL出错!");
}
//window.confirm("下载完成.");
}
</script>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="80%">
<tr>
<td width="100%" valign="top">测试XMLHTTP</td>
</tr>
</table>
kw123
2004-09-08
打赏
举报
回复
当然是本地,从服务器中得到数据流
chancelin
2004-09-08
打赏
举报
回复
你是想把文件保存导服务器上?
HuaDongcn
2004-09-08
打赏
举报
回复
up
gjd111686
2004-09-08
打赏
举报
回复
byte[] pFileExtend=new byte[1024];
FileOutputStream pFileOutputStream=new FileOutputStream("F:\\Site_ColligateStatistic\\UploadFile\\"+strFileName);
pFileOutputStream.write(pFileExtend);
pFileOutputStream.close();
kw123
2004-09-08
打赏
举报
回复
?????????????
jsp
实现
文件
保存
与读取
@ page language="java" import="java.util.*" pageEncoding="GBK"%> @ page contentType="text/html; charset=GBK" %> @page import="java.io.File"%> @page import="java.io.PrintStream"%> @page import="java.io
jsp
怎么将服务器
文件
保存
,关于
jsp
保存
文件
到服务器-
JSP
教程,
Jsp
/Servlet
关于
jsp
保存
文件
到服务器在html
中
调用xml数据public string savexml(string textxml){string guestbookpath=getservletcontext().getrealpath("/
jsp
save.
jsp
");try{java.io.filewriter fw=new java.io.filewriter(guestbookpath+"\gu...
JSP
上传
文件
到
指定
位置
复制上传
文件
,上传
文件
到服务器
指定
位置,注意,提交表单需要制定enctype的类型。具体代码如下: Servlet 代码: /** 直接取上传的File */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOExcepti
在html页面上实现弹出
对话框
,选择
文件
保存
路径
,js获取a标签download弹出另存为
对话框
的
路径
。...
在html或者
jsp
中
弹出
文件
另存为的
对话框
,可以调用document.execCommand方法调用JS方法document.execCommand即可在前台页面调出另存为
对话框
,并将将服务器上存放的
文件
保存
到本地。HTML页面另存为
对话框
DEMO.rar代码:functiongetimg()//另存为存放在服务器上图片到本地的方法{event.returnValue=false;show....
为什么
文件
上传成功后在
指定
的
路径
中
找不到上传的
文件
这是后台代码 package com.cao.test.action; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; impor...
Web 开发
81,108
社区成员
341,721
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章