读书人

睡不下啊呀救救小弟我吧就一道题

发布时间: 2012-01-31 21:28:41 作者: rapoo

睡不下啊。在线等呀,救救我吧,就一道题
这是jsp的bean源文件 UpFile

编辑的时候出现了点问题


servlet-api.jar包已经复制到jdk安装目录下了jre\lib\ext,但还是出了错,求解啊。。。。。睡不下啊




Java code
package user.file;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.RandomAccessFile;import javax.servlet.http.*;public class UpFile {    HttpServletRequest request;    HttpSession session;    String upFileMessage="";    public void setRequest(HttpServletRequest request){        this.request=request;    }    public void setSession(HttpSession session){        this.session=session;    }    public String getUpFileMessage(){        String fileName=null;        try{            String tempFileName=(String)session.getID();            File f1=new                     File("d:/java",tempFileName);            FileOutputStream o=new FileOutputStream(f1);            InputStream in=request.getInputStream();            byte b[]=new byte[1000];            int n;            while((n=in.read(b))!=-1){                o.write(b,0,n);            }            o.close();            in.close();            RandomAccessFile random=new RandomAccesFile(f1,"r");            int second=1;            String secondLine=null;            while(second<=2){                secondLine=random.readLine();                second++;                int position=secondLine.lastIndexOf('\\');                fileName=secondLine.substring(position+1,secondLine.length()-1);                byte cc[]=fileName.getBytes("ISO-8859-1");                fileName=new String(cc);                session.setAttribute("Name",fileName);                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:/java",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();                upFileMessage=fileName+"Successfully UpLoad";                return upFileMessage;            }        }            catch(Exception exp){                Object fileName1;                if((fileName!=null)){                    upFileMessage=fileName+"Fail to UpLoad";                    return upFileMessage;                }                else{                    upFileMessage="";                    return upFileMessage;                }            }        }    }


[解决办法]
谁有耐心看你那么长的代码 把报的异常贴出来

可以帮你分析 也许有用的
[解决办法]
结贴率太低了
不知道你这个能不能上传文件,但我感觉不大对


首先要获取boundary,根据boundary分割每个域,然后判断各个域属于那种类型,是流还是文本,如果是文本那么就获取文本的名称和内容,如果是数据流内容,那么就是上传的文件
[解决办法]
把问题说清楚啊
[解决办法]
谁有耐心看你那么长的代码 把报的异常贴出来

可以帮你分析 也许有用的
[解决办法]
结贴率实在太低了,我推测你人品不太好啊

读书人网 >Java Web开发

热点推荐