⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shangchuan.jsp

📁 jsp做的一个个人网站
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*,javax.servlet.http.*"%>
<body bgcolor="#99CCCC" >
<%
        String fileName=null;
        try
        {//用用户的session对象的ID建立临时文件
            String tempFileName=(String)session.getId();
            //建立临时文件f1
            File f1=new File("D://",tempFileName);
            FileOutputStream o=new FileOutputStream(f1);
            //将客户上传的全部信息存入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();
            //读取临时文件f1,从中获取上传文件的名字和上传文件的内容
            RandomAccessFile random=new RandomAccessFile(f1,"r");
            //读取f1的第2行,获取上传文件的名字
            int second=1;
            String secondLine=null;
            while(second<=2)
            {
               secondLine=random.readLine();
               second++;
            }
            //获取第2行中目录符号‘\’最后出现的位置
            int position=secondLine.lastIndexOf('\\');
            //客户上传文件的名字是
            fileName=secondLine.substring(position+1,secondLine.length()-1);
            random.seek(0);//再定位到文件f1的开头
            //获取第4行回车符的位置
            long forthEndPosition=0;
            int forth=1;
            while((n=random.readByte())!=-1&&(forth<=4))
            {
              if(n=='\n')
              {
                 forthEndPosition=random.getFilePointer();
                 forth++;
              }
            }
            //根据客户上传文件的名字,将该文件存入磁盘
            byte cc[]=fileName.getBytes("ISO-8859-1");
            fileName=new String(cc);
            File f2=new File("D://",fileName);
            session.setAttribute("Name",fileName);
            RandomAccessFile random2=new RandomAccessFile(f2,"rw");
            //确定文件f1中包含客户上传文件的内容的最后位置,即倒数第6行
            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流指向文件f1的第4行结束的位置
            random.seek(forthEndPosition);
            long startPoint=random.getFilePointer();
            //从f1读出客户上传的文件存入f2
            while(startPoint<endPosition-1)
            {
              n=random.readByte();
              random2.write(n);
              startPoint=random.getFilePointer();
             }
            random2.close();
            random.close();
            f1.delete();%>
		
     <%   }
        catch(IOException ee){}
        out.print("文件上传成功!");
	 %>
	<table border="0"><tr><td width="67"><a href="D:/<%=fileName%>">查看</a></td>
	</tr></table>	
		
   
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -