作者:ztyzty
下面是一个用来上传下达的小
程序,希望大家给予指教.
import java.io.*;
import java.util.*;
import java.text.*;
import javax.mail.*;
import javax.servlet.*;
import javax.activation.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
import javax.mail.internet.MimeMultipart;
/**
* @author 2002/7/10 zty
*
*<p>
*<p> 【使用例】
*<p> try {
*<p> Upload load=new Upload();
*<p> load.setDir("i:\\ztytest\\"); *<p> load.doUpload(req,res); *<p> //HttpServletRequest req
*<p> //HttpServletResponse res
*<p> }
*<p> catch( Exception e ) {
*<p> return;
*<p> }
*/
public class Upload extends HttpServlet {
public String strDir;
public Upload()
{
}
public void doUpload(HttpServletRequest req, HttpServletResponse res)
throws IOException,MessagingException
{
String boundary=req.getHeader("Content-Type");
int pos=boundary.indexOf(''='');
boundary=boundary.substring(pos+1);
boundary="--"+ boundary;
ServletInputStream in=req.getInputStream() ;
byte bytes=new byte[512];
int state=0;
ByteArrayOutputStream buffer=new ByteArrayOutputStream();
String name=null;
String value=null;
String filename=null;
String contentType=null;
int i=in.readLine(bytes,0,512);
while (-1!=i)
{
String st=new String(bytes,0,i);
if (st.startsWith(boundary))
{
state=0;
&