如果可以最好能带点注释.. 我在BAIDU 搜了N多基本都一样的.大家最好能提供个完整的.谢谢
解决方案 »
- Struts2单元测试的问题
- tomcat 能否隐藏URL?
- 新手提问:jsp文件放在WEB-INF下,tld文件和web.xml文件要怎样写才能正常应用taglib
- JSP如何把数据库中的科学计数数据转换成普通计数显示到页面?
- 有关ECLIPSE下的TOMCAT调试
- 怎样设置一个页面,每当IE载入它时就变成全屏显示。
- 快呀高入求救呀!!!!!!!!!!!!
- 小妹的一个弱问题!刚从delphi转过来,很不适应!(问题在里面)我的qq:345731598 欢迎和我联系!
- servlet读取xml,xml放在哪?
- 本人想学JSP,请各位推荐几本好书,谢谢,希望不会太厚.
- 在tomcat里如何配置server.xml
- Hibernate中保存一个对象,出错
try{
String temp=(String)session.getId();
File f1=new File((String)request.getRealPath("photo")+"/",temp);//f1对象指向上传文件的所在路径
out.println(f1);
FileOutputStream o=new FileOutputStream(f1);//文件输出流指向上传文件所在路径
out.println(o);
InputStream in=request.getInputStream();//得到客户端所提交的数据
byte b[]=new byte[10000000];
int n;
while((n=in.read(b))!=-1){
o.write(b,0,n);
}
o.close();
in.close();
//读取临时文件f1,从中获取上传文件的名字和上传文件的内容。
RandomAccessFile random=new RandomAccessFile(f1,"r");//r代表只读
int second=1;
String secondLine=null;
while(second<=2){
secondLine=random.readLine();
second++;
}
int position=secondLine.lastIndexOf('\\');
String fileName=new String((secondLine.substring(position+1,secondLine.length()-1)).getBytes("iso-8859-1"), "GB2312");
random.seek(0);//重新定位使文件指针指到文件头
long forthEnPosition=0;
int forth=1;
while((n=random.readByte())!=1&&(forth<=4)){//取到第四行回车符号所在位置,这是上传文件的开始位置
if((n=='\n')){
forthEnPosition=random.getFilePointer();
forth++;
}
}
File f2=new File((String)request.getRealPath("photo")+"/",fileName);
session.setAttribute("Name",fileName);//将文件保存入SESSION
RandomAccessFile random2=new RandomAccessFile(f2,"rw");
random.seek(random.length());
long endPosition=random.getFilePointer();
long =endPosition;
int j=1;
while((>=0)&&(j<=6)){//找到上传文件数据结束的位置,即倒数第六行
--;
random.seek();
n=random.readByte();
if(n=='\n'){
endPosition=random.getFilePointer();
j++;
}
}
random.seek(forthEnPosition);
long startPoint=random.getFilePointer();
while(startPoint<endPosition-1){//从上传文件数据开始的位置到数据结算的位置,把数据写入TOMCAT下的PHOTO子目录中,以SESSIONID命名
n=random.readByte();
random2.write(n);
startPoint=random.getFilePointer();
}
random2.close();
random.close();
f1.delete();
out.println("<script language='javascript'>alert('上传成功');window.close();opener.form1.Photo.value='../photo/"+fileName+"';</script>");
}catch(IOException e){
out.println("文件上传失败");
}
%>
http://10000.245.3098.com/upload/ 这里是运行的.
你好像没导入包