jsp 로 파일 을 작성 하여 업로드 합 니 다.

파일 로 올 린 구성 요 소 를 VB 로 작성 한 적 이 있다 면,파일 로 올 린 JAVABEAN 을 JAVA 로 작성 하 는 것 은 매우 쉽다.아래 의 예 는 단지 간단 한 패키지 유 니 피 플 업 입 니 다.import java.io.*;import java.util.*;import javax.servlet.*;import javax.servlet.http.*;import javax.servlet.jsp.PageContext;public class yuanyifileup{private ServletRequest request;private ServletResponse response;private ServletConfig config;ServletInputStream DATA;int FormSize;File f1;FileOutputStream os;DataInputStream is;String filename;byte[] b;byte t;boolean flag=false;public yuanyifileup(){ }public void initialize(ServletConfig config,HttpServletRequest request,HttpServletResponse response) throws IOException{this.request=request;this.response=response;this.config=config;DATA = request.getInputStream();FormSize=request.getContentLength();}public void initialize(PageContext pageContext) throws IOException{request=pageContext.getRequest();response=pageContext.getResponse();config=pageContext.getServletConfig();DATA = request.getInputStream();FormSize=request.getContentLength();}public boolean setFilename(String s){try{File f1=new File(s);os=new FileOutputStream(f1);}catch(IOException e){return(false);}return(true);}public void getByte(){int i=0;try{is=new DataInputStream(DATA);b=new byte[FormSize];while (true){try{t=is.readByte();b[i]=t;i++;}catch(EOFException e){ break;}}is.close();}catch(IOException e){}}public boolean save(){int i=0,start1=0,start2=0;String temp="";if (!flag){getByte();flag=true;}try{temp=new String(b,"ISO8859_1");}catch(UnsupportedEncodingException e){return(false);}start1=temp.indexOf("image/");temp=temp.substring(start1);start1=temp.indexOf("\r\r");temp=temp.substring(start1+4);start2=temp.indexOf(";\r");if (start2!=-1){temp=temp.substring(0,start2); }try{byte[] img=temp.getBytes("ISO8859_1");for (i=0;i

좋은 웹페이지 즐겨찾기