Se o que voc� quer � fazer um upload o c�digo est� abaixo:
//-------
//-
//- upload.java
//-
//- Author: AR Williamson
//- Date: May 1998
//- Copyright: Maybe used for non-commercial use.
//-
//-------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class upload extends HttpServlet {
public void doPost( HttpServletRequest _req, HttpServletResponse _res
) throws ServletException, IOException{
parseMultiForm pMF = new parseMultiForm( _req );
String param;
while ( (param = pMF.getNextParameter()) != null ){
if ( param.equalsIgnoreCase("USERFILE") ){
FileOutputStream OutFile = new FileOutputStream(
pMF.getFilename() );
pMF.getParameter( OutFile );
OutFile.close();
}else{
System.out.println( "Key : " + param );
System.out.println( "Value: " + pMF.getParameter() );
}
}
_res.setStatus( HttpServletResponse.SC_NO_CONTENT );
}
}
class parseMultiForm extends java.lang.Object {
private ServletInputStream In;
private byte buffer[] = new byte[4096];
private String delimitor = null;
private String filename=null;
public parseMultiForm( ServletRequest _req ) throws IOException{
In = _req.getInputStream();
delimitor = _req.getContentType();
if ( delimitor.indexOf("boundary=") != -1 ){
delimitor = delimitor.substring( delimitor.indexOf("boundary=")+9,
delimitor.length() );
delimitor = "--" + delimitor;
}
}
private String readLine(){
try{
int noData = In.readLine( buffer, 0, buffer.length );
if ( noData != -1 )
return new String( buffer, 0, noData, "ISO-8859-1");
}catch(Exception E){}
return null;
}
void test() throws IOException{
String LineIn;
while( (LineIn=readLine()) != null )
System.out.println( LineIn );
}
public String getFilename(){
return filename;
}
public String getParameter(){
return readLine();
}
public String getNextParameter() {
try{
String LineIn=null, paramName=null;
while ( (LineIn=readLine()) != null ){
if ( LineIn.indexOf( "name=" ) != -1 ){
int c1 = LineIn.indexOf( "name=" );
int c2 = LineIn.indexOf( "\"", c1+6 );
paramName = LineIn.substring( c1+6, c2 );
if ( LineIn.indexOf( "filename=") != -1 ){
c1 = LineIn.indexOf( "filename=" );
c2 = LineIn.indexOf( "\"", c1+10 );
filename = LineIn.substring( c1+10, c2 );
if ( filename.lastIndexOf( "\\" ) != -1 )
filename = filename.substring( filename.lastIndexOf( "\\"
)+1 );
if ( filename.length() == 0 )
filename = null;
}
//- Move the pointer to the start of the data
LineIn = readLine();
if ( LineIn.indexOf( "Content-Type" ) != -1 )
LineIn = readLine();
return paramName;
}
}
}
catch( Exception E ){}
return null;
}
public boolean getParameter( OutputStream _Out ){
try{
int noData;
while ( (noData=In.readLine(buffer,0,buffer.length)) != -1 ){
if ( buffer[0] == '-' ){
if ( new String( buffer, 0, noData,
"ISO-8859-1").indexOf(delimitor) == 0 )
break;
}else
_Out.write( buffer, 0, noData );
}
_Out.flush();
return true;
}
catch( Exception E ){
System.out.println( E );
}
return false;
}
}
Espero ter ajudado.
Abra�os.
> Alessandro Boeira dos Reis wrote:
>
> Ola pessoal,
>
> alguem sabe como fazer um download de um arquivo local (fora do
> servidor de web) a partir de uma Servlet???
>
> Desde ja grato,
> Alessandro.
--
**********************************************************
Handerson Ferreira Gomes, Analista de Sistemas
CITS - Centro Internacional de Tecnologia de Software
Depto: CNTS - Centro de Novas Tecnologias de Software
Parque de Software de Curitiba
81230-000 Curitiba, PR, Brasil
+55 41 317 2086, fax: 337 1002
http://www.cits.br
**********************************************************
* Para nao receber mais e-mails da lista, acesse
<http://www.sun.com.br:8080/guest/RemoteAvailableLists>, coloque seu e-mail, escolha a
lista <[EMAIL PROTECTED]> e de um <submit>.