当前位置: 代码迷 >> Java Web开发 >> 晚上好,各位麻烦辛苦帮忙看下这程序,感激不尽解决思路
  详细解决方案

晚上好,各位麻烦辛苦帮忙看下这程序,感激不尽解决思路

热度:150   发布时间:2016-04-17 10:55:31.0
晚上好,各位麻烦辛苦帮忙看下这程序,感激不尽
下面是的 jsp 程序实现文件上传功能 遇到点问题 请各位麻烦帮小弟看看 谢谢了~~!!!

servle-api.jar我已经复制到jdk安装目录中 jre\lib\ext

出现的问题提示是-----“Access restriction: The type HttpServletRequest is not accessible due to restriction on required library D:\java\jdk-7\jre\lib\ext\servlet-api.jar”


以下是问题的程序


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 upUileMessage="";    public void setRequest(HttpServletRequest request){        this.request=request;    }    public void setSession(HttpSession session){        this.session=session;    }    public String getUpFileMessage(){        String fileName=null;        String upFileMessage;        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(o);                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;                }            }        }    }


------解决方案--------------------
发错地方了 年轻人
------解决方案--------------------
  相关解决方案