📄 acceptfile.jsp.bak
字号:
<HTML>
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.io.*" %>
<BODY bgcolor=cyan><Font size=3>
<% try
{
String tempFileName=(String)session.getId();
File f1=new File("d:/Tomcat/webapps/ROOT/chap4",tempFileName);
FileOutputStream o=new FileOutputStream(f1);
InputStream in=request.getInputStream();
byte b[]=new byte[10000];
int n;
while((n=in.read(b))!=-1)
o.write(b,0,n);
o.close();in.close();
RandomAccessFile random=new RandomAccessFile(f1,"r");
int second=1;
String secondLine=null;
while(second<=2)
{
secondLine=random.readLine();
second++;
}
int position=secondLine.lastIndexOf('\\');
String fileName=secondLine.substring(position+1,secondLine.length()-1);
random.seek(0);
long forthEndPosition=0;
int forth=1;
while((n=random.readByte())!=-1&&(forth<=4))
if(n=='\n')
{
forthEndPosition=random.getFilePointer();
forth++;
}
File f2=new File("d:/Tomcat/webapps/ROOT/chap4",fileName);
session.setAttribute("Name",fileName);
RandomAccessFile random2=new RandomAccessFile(f2,"rw");
random.seek(random.length());
long endPosition=random.getFilePointer();
long mark=endPosition;
int j=1;
while((mark>=0)&&(j<=6))
{
mark--;
random.seek(mark);
n=random.readByte();
if(n=='\n')
{
endPosition=random.getFilePointer();
j++;
}
}
random.seek(forthEndPosition);
long startPoint=random.getFilePointer();
while(startPoint<endPosition-1)
{
n=random.readByte();
random2.write(n);
startPoint=random.getFilePointer();
}
random2.close();random.close();
f1.delete();
}catch(IOException ee){}
out.print("文件已上传");
%>
<P>查看上传的图像效果
<% String str=response.encodeURL("showImage.jsp");
%>
<FORM action="<%=str%>" >
<BR><INPUT type="submit" value="查看" >
</ FORM >
</FONT>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -