📄 receive2.jsp
字号:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>
receieve
</title>
</head>
<body bgcolor="#ffffff">
<br>
<%
String filename=session.getAttribute("select15").toString();
session.removeAttribute("select15");
System.out.println("filename===2222=="+filename);
String tempFile = new String("mytempfile");
File temp = new File("../\\webapps\\dazhe\\WEB-INF", tempFile);
FileOutputStream o = new FileOutputStream(temp);
InputStream fileSource = null;
fileSource = request.getInputStream();
byte[] b = new byte[8192];
int n;
while((n = fileSource.read(b)) != -1) {
o.write(b, 0, n);
o.flush();
}
fileSource.close();
o.close();
String strDirPath = this.getServletContext().getRealPath("/pic");
RandomAccessFile rf = new RandomAccessFile(temp, "r");
rf.readLine();
String FilePath = rf.readLine();
int position = FilePath.lastIndexOf('\\');
rf.seek(0);
long forthEnterPosition = 0;
int forth = 1;
while((n = rf.readByte()) != -1 && (forth <= 4)) {
if(n == 10) {
forthEnterPosition = rf.getFilePointer();
forth++;
}
}
String pic="\\"+System.getProperty("file.separator")+"pic";
File FileUploadDir = new File(strDirPath);//Tomcat的默认路径是其安装路径下的/bin目录下
FileUploadDir.mkdir();
File savefile = new File(strDirPath, filename);//上传到当前服务的/WEB-INF目录下
RandomAccessFile rf2 = new RandomAccessFile(savefile, "rw");
rf.seek(rf.length());
long endPosition = rf.getFilePointer();
int j = 1;
while((endPosition>=0) && (j<=2)) {
endPosition--;
rf.seek(endPosition);
if(rf.readByte() == 10)
j++;
}
rf.seek(forthEnterPosition);
long startPoint = rf.getFilePointer();
while(startPoint + 8192L <= endPosition-1) {
n = rf.read(b);
startPoint = rf.getFilePointer();
rf2.write(b, 0, n);
}
while(startPoint < endPosition-1) {
rf2.write(rf.readByte());
startPoint = rf.getFilePointer();
}
rf2.close();
rf.close();
temp.delete();
%>
<script language="javascript">
<!--
alert("图片传输成功");//弹出要显示的信息
self.location.replace('selectType.jsp');//要转向的页面
-->
</script>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -