Mauricio Villa:
ÔÚ 01-3-18 19:36:00 ÄúдµÀ£º
>Hi,
>
>Anyone knows how can I do a file upload from one client to one directory
>on the server? one one of you have an example. I am a newbie in jsp and
>servlets.
>
>Thanks in advance,
>
>__________________________
>Mauricio A. Villa Sierra
>Microsoft Certified Professional
>Solutech e-Business
>Tel. 3120019 EXT 13
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
/////////////////////////////////////////////////////////////////////
Pls look at this is method,I do a file upload with this successfully!
/////////////////////////////////////////////////////////////////////
private String UploadFile(String s, String s1, String s2, ServletInputStream
servletinputstream, String s3)
throws ServletException, IOException
{
String s6 = null;
String s7 = "";
byte abyte0[] = new byte[4096];
byte abyte1[] = new byte[4096];
int ai[] = new int[1];
int ai1[] = new int[1];
long l = 0L;
String s8 = getId();
String s4;
while((s4 = readLine(abyte0, ai, servletinputstream, s3)) != null)
{
int i = s4.indexOf("filename=");
if(i >= 0)
{
s4 = s4.substring(i + 10);
i = s4.indexOf("\"");
if(i > 0)
s4 = s4.substring(0, i);
break;
}
}
if(s != null)
s4 = s;
s7 = s4;
if(s7 != null)
{
s7 = getFileName(s7);
String s5 = readLine(abyte0, ai, servletinputstream, s3);
if(s5.indexOf("Content-Type") >= 0)
readLine(abyte0, ai, servletinputstream, s3);
File file = new File(s1, s8);
FileOutputStream fileoutputstream = new FileOutputStream(file);
while((s5 = readLine(abyte0, ai, servletinputstream, s3)) != null)
{
l++;
if(s5.indexOf(s2) == 0 && abyte0[0] == 45)
break;
if(s6 != null && l <= 75L)
{
fileoutputstream.write(abyte1, 0, ai1[0]);
fileoutputstream.flush();
}
s6 = readLine(abyte1, ai1, servletinputstream, s3);
if(s6 == null || s6.indexOf(s2) == 0 && abyte1[0] == 45)
break;
fileoutputstream.write(abyte0, 0, ai[0]);
fileoutputstream.flush();
}
byte byte0;
if(newline.length() == 1)
byte0 = 2;
else
byte0 = 1;
if(s6 != null && abyte1[0] != 45 && ai1[0] > newline.length() * byte0)
fileoutputstream.write(abyte1, 0, ai1[0] - newline.length() * byte0);
if(s5 != null && abyte0[0] != 45 && ai[0] > newline.length() * byte0)
fileoutputstream.write(abyte0, 0, ai[0] - newline.length() * byte0);
fileoutputstream.flush();
fileoutputstream.close();
try
{
synchronized(forLock1)
{
File file1 = new File(s1, s7);
try
{
file1.delete();
}
catch(Exception _ex) { }
file.renameTo(file1);
}
}
catch(Exception _ex) { }
}
else
{
throw new IOException();
}
return s7;
}
regard!
[EMAIL PROTECTED]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html