Write file upload with JSP

xiaoxiao2021-03-06  49

This article repost!

If you have written files uploaded by VB, JavaBean uploaded by Java is very easy.

The following example is just a simple package yuanyiFileup; import java.io. *; Import java.util. *; Import javax.servlet. *; Import javax.servlet.http. *; Import javax.servlet.jsp.pagecontext; public.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 file OutputStream (f1);} caturn (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 (ooException 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 (unsupporteencodingExcection e) {return (false);} start1 = temp.indexof ("image /"); temp = temp.substring (start1); start1 = Temp.indexof ("/ r /n/r/n" ";TEMP=TEMP.SUBSTRING (START1 4 );start2=

转载请注明原文地址:https://www.9cbs.com/read-117113.html

New Post(0)