求帮忙修改上传代码(在linux系统下)
在xp、2003系统下能正常运行,在linux系统下出错
具体:错误原因
获得endPos的值,在linux系统下与其他系统下不一致
代码如下
具体:错误原因
endPos = ((file.substring(0,boundaryLocation)).getBytes()).length; 获得endPos的值,在linux系统下与其他系统下不一致
代码如下
<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<html>
<head>
<title> upFile </title>
</head>
<body bgcolor="#ffffff">
<center>
<%
String rootPath;
DataInputStream in = null;
FileOutputStream fileOut = null;
String realPath = request.getRealPath("/");
rootPath = realPath + "/upload/";
String contentType = request.getContentType();
try{
if(contentType.indexOf("multipart/form-data") >= 0){
in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes,totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0,saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
String fileName = rootPath + saveFile;
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n",pos) + 1;
pos = file.indexOf("\n",pos) + 1;
pos = file.indexOf("\n",pos) + 1;
int boundaryLocation = file.indexOf(boundary,pos) - 4;
int startPos = ((file.substring(0,pos)).getBytes()).length;
int endPos = ((file.substring(0,boundaryLocation)).getBytes()).length;
File checkFile = new File(fileName);
if(checkFile.exists()){
return;
}
File fileDir = new File(rootPath);
if(!fileDir.exists()){
fileDir.mkdirs();
}
fileOut = new FileOutputStream(fileName);
fileOut.write(dataBytes,startPos,(endPos - startPos));
fileOut.close();
}else{
String content = request.getContentType();
}
}catch(Exception ex){
throw new ServletException(ex.getMessage());
}
%>
</center>
</body>
</html>
...全文
相关推荐
Linux 内核代码修改
Linux 内核代码修改,在国外课程第一次修改linux内核
linux系统上传下载命令rz和sz的教程
主要介绍了linux系统上传下载命令rz和sz的安装测试方法,需要的朋友可以参考下
Linux修改系统时区
1. 查看当前时区 # vi /etc/sysconfig/clock 2. 修改设置时区 方法(1) # tzselect 方法(2 仅限于RedHat Linux 和 CentOS) # timeconfig 3. 复制相应的时区文件,替换系统默认时区 # cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime 对于中国服务器则执行: # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 4. 将当前时间写入BIOS永久生效(避免重启后失效) # hwclock
linux系统语言修改方法
linux系统语言修改方法
kali linux修改系统语言为中文的方法
内容由本人整理,过程很详细,图文并茂,适合linux新手学习。


Web 开发
