<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>The real file</title>
</head>
<body>
<%try{
//use sessionid to create a temp file.
String tempFileName=(String)session.getId();
//create the temp file.
File temp=new File("d:/temp",tempFileName);
FileOutputStream o=new FileOutputStream(temp);
if(request.getContentLength()>297){
//write the upload content to the temp file.
InputStream in=request.getInputStream();
byte b[]=new byte[1024];
int n;
while((n=in.read(b))!=-1){
o.write(b,0,n);
}
o.close();
in.close();
//read the temp file.
RandomAccessFile random=new RandomAccessFile(temp,"r");
//read Line2 to find the name of the upload file.
int second=1;
String secondLine=null;
while(second<=2){
secondLine=random.readLine();
second++;
}
//get the last location of the dir char.'\\'.
int position=secondLine.lastIndexOf('\\');
//get the name of the upload file.
String fileName=secondLine.substring(position+1,secondLine.length()-1);
//relocate to the head of file.
random.seek(0);
//get the location of the char.'Enter' in Line4.
long forthEndPosition=0;
int forth=1;
while((n=random.readByte())!=-1&&(forth<=4)){
if(n=='\n'){
forthEndPosition=random.getFilePointer();
forth++;
}
}
File realFile=new File("d:/temp",fileName);
RandomAccessFile random2=new RandomAccessFile(realFile,"rw");
//locate the end position of the content.Count backwards 6 lines.
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++;
}
}
//locate to the begin of content.Count for 4 lines's end position.
random.seek(forthEndPosition);
long startPoint=random.getFilePointer();
//read the real content and write it to the realFile.
while(startPoint<endPosition-1){
n=random.readByte();
random2.write(n);
startPoint=random.getFilePointer();
}
random2.close();
random.close();
//delete the temp file.
temp.delete();
out.print("File upload success!");
}
else{
out.print("No file!");
}
}
catch(IOException e){
out.print("upload error.");
e.printStackTrace();
}
%>
</body>
</html>
zhangjunhd 51cto技术博客
相关推荐
JSP实现文件上传与下载.pdf
1,只需要将文件夹upload拷在...3,有jsp文件上传与下载攻略是讲文件上传与下载的各种类中的函数含义的 4,主要包括完整的 jspsmartupload上传与下载,还有jspsmartupload的完整包,并且包括包中各种上传与下载的解释
使用jspSmartUpload实现文件上传下载,包含SmartUpload方法注解、上传示例及组件包
JSP实现文件的上传与下载,方便大家参考使用,实在方便,用到了文件上传组件,但是下载没有,大家参考参考学习学习,定会有所收获的。
jspsmart实现文件上传下载及jspSmartUpload.jar下载.txt jspsmart实现文件上传下载及jspSmartUpload.jar下载.txt
利用jsp实现文件上传下载,将文件上传到tomcat服务器之后下载。
jspSmartUpload实现文件上传下载
主要讲解使用jspSmartupload组件在实现文件的上传与下载.欢迎学习交流,qq:634229897
jsp实现文件的上传下载,关于JSP文件的上传和下载功能的实现,
很好用的一个jsp文件上传下载开源,村!!!!!!!
jsp实现文件上传下载功能
利用Javabean+JSP 实现文件的上传、显示、下载 实现文件上传功能和下载功能,显示文件列表和读取文件内容功能。
JSP中如何实现文件的上传和下载的Word教学文档。
jsp实现上传和下载,导入项目后可以直接使用。
使用JSP实现上传下载文件jspSmartUpload 里面讲述怎么用jsp实现
利用jsp实现文件的上传和下载,真的很不错,不信你可以看一下
使用JSP实现文件的上传和下载,在同一项目的业务处理
在网上找到一个不错的文件的上传和下载的教材 感觉不错就整理和大家分享 其中包含了教材和自己整理的一个jspsmartUpload.jar
jspsmart实现文件上传下载及jspSmartUploadjar下载文库.pdf
CKEditor在jsp中实现文件上传,java应用