将华表文件以二进制流的方式发送到服务器端。
[Visual Basic]
UploadFile(ServerURL As String) As Long
返回值
返回值 描述
1 传送成功
0 数据传输失败
-1 URL地址错误
-2 不能打开网络连接对话
-3 不能建立连接
-4 不能建立响应对象
-5 关闭响应对象失败
-6 关闭连接对象失败
-7 关闭对话对象失败
参数
客户端代码:
function upLoadCell(filename)
{
var a=cell.UploadFile("../ifmis/fasp/jsp/performance/uploadCell.jsp?filename="+filename);
if(a==1)
{
alert("保存成功!");
}
else
{
alert("保存失败!");
}
}
服务器端接收
public void upLoad(HttpServletRequest request,HttpServletResponse response) throws AppException, Exception {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String path = DicFind.getSysCfgParam("FILEPATH", "EXCEL");
String filname=request.getParameter("filename")+".cll";
InputStream in = request.getInputStream();
//List list=new ArrayList();
//list.add("elementvalue");
//List<Map> list1=dao.query("t_appsyscfg", list, "scenecode='FILEPATH' and elementcode='EXCEL'");
//String strUrl =(String)list1.get(0).get("elementvalue") ;
File file = new File((path+"/"+filname).toString());
if(!file.exists())
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[1000];
int index = -1;
while((index = in.read(buffer))!= -1)
{
out.write(buffer,0,index);
}
out.close();
}
[Visual Basic]
UploadFile(ServerURL As String) As Long
返回值
返回值 描述
1 传送成功
0 数据传输失败
-1 URL地址错误
-2 不能打开网络连接对话
-3 不能建立连接
-4 不能建立响应对象
-5 关闭响应对象失败
-6 关闭连接对象失败
-7 关闭对话对象失败
参数
客户端代码:
function upLoadCell(filename)
{
var a=cell.UploadFile("../ifmis/fasp/jsp/performance/uploadCell.jsp?filename="+filename);
if(a==1)
{
alert("保存成功!");
}
else
{
alert("保存失败!");
}
}
服务器端接收
public void upLoad(HttpServletRequest request,HttpServletResponse response) throws AppException, Exception {
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String path = DicFind.getSysCfgParam("FILEPATH", "EXCEL");
String filname=request.getParameter("filename")+".cll";
InputStream in = request.getInputStream();
//List list=new ArrayList();
//list.add("elementvalue");
//List<Map> list1=dao.query("t_appsyscfg", list, "scenecode='FILEPATH' and elementcode='EXCEL'");
//String strUrl =(String)list1.get(0).get("elementvalue") ;
File file = new File((path+"/"+filname).toString());
if(!file.exists())
file.createNewFile();
OutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[1000];
int index = -1;
while((index = in.read(buffer))!= -1)
{
out.write(buffer,0,index);
}
out.close();
}
本文介绍了一种使用Visual Basic实现的华表文件二进制流上传方法,客户端通过特定函数将文件发送到服务器,服务器端采用Java处理请求,完成文件的保存。
922

被折叠的 条评论
为什么被折叠?



