I saw sb used ASP ActiveX to upload image files from HTML file tags, I
tried to write a java version.
It's a stand alone instead of a servlet. It used to work, but lately I tried
it again and want to change it to a servlet to use in my jsp page. But it
just won't work anymore.
This is what I did: first start the web server (pws or IIS),load the HTML
page containing the <input type="file"> tag. then choose an image. After
that, I kill the web server and instead use my java program to recieve the
request,and click the submit button on the HTML page. An image file is
suppose to be stored in the assigned path and it used to work quite well.
But this time nothing.
The following is my code. Sorry it a longer. If anybody interested pls have
a look:
********************
import java.io.*;
import java.net.*;
public class UpLoad
{
public static void main(String args[])
{
int ch,ch1,ch2,ch3,ch4=0,ch5=0,ch6=0,ch7=0;
byte[][] b=new byte[5][50000];
int[] count=new int[5];
try
{
ServerSocket s=new ServerSocket(80);
int localport=s.getLocalPort();
System.out.println("Server listening on local port"+localport);
Socket client=s.accept();
DataInputStream is=new DataInputStream(client.getInputStream());
int j=1,k=0,l=0;
while(true)
{
ch4=0;ch5=0;ch6=0;ch7=0;
if(((char)(ch=is.read())=='\r')&&((char)(ch1=is.read())=='\n')
&&((char)(ch2=is.read())=='\r')&&((char)(ch3=is.read())=='\n'))
{
System.out.println(" Two CRLF met!");
}
if(j==1){j=2;}
else
{
scan:
for(int i=0;;i++)
{
System.out.println("read"+i);
if(((char)(ch4=is.read())=='\r')&&((char)(ch5=is.read()
)=='\n')
&&((char)(ch6=is.read())=='-')&&((char)(ch7=is.read()
)=='-'))
{
System.out.println("End of an IMAGE");
DataOutputStream os=new DataOutputStream(new
FileOutputStream(
"c:/temp/temp"+l+".gif"));
count[l]=k;
k=0;
os.write(b[l],0,count[l]);
os.close();
os=null;
l=l+1;
break scan;
}
else if((char)ch4=='\r')
{
b[l][i]=(byte)ch4;
b[l][i+1]=(byte)ch5;
k=i+1;
if((char)ch5=='\n')
{
b[l][i+2]=(byte)ch6;
k=i+2;
if((char)ch6=='\r')
{
b[l][i+3]=(byte)ch7;
k=i+3;
}
}
}
else {
b[l][i]=(byte)ch4;
}
i=k;
k=k+1;
System.out.println("goooo number"+l);
System.out.println(""+b[l][i]);
}
}
}
}
}
catch(Exception e)
{
System.out.println("Exception encountered"+e);
}
}
}
*************************************************************
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets