Hi,

------------------Please Help me

Is there any way to transfer the file Streams from one servlet to another servlet ???????????????

Using TomcatServer.

I need to upload a file in two steps i.e in two servlets.

In 1st servlet I need convert the File into Streams and to send for the second servlet.

In my firstServlet Iam writing the FileInputstream into response object and forwarding it.

In my SecondServlet Iam writing the Inputstream into FileOutputStream object.

but Iam unable to forward the request from first servlet using RequestDispatcher's forward(req,res) method (getting exception as response is already commited before forwarding)

1st servlet:

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.Locale;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;





public class UploadServlet extends HttpServlet

{

public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
System.out.println("in UploadServlet");
try
{

FileInputStream fis=new FileInputStream("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/sample1.txt");
int i=0;
OutputStream os=response.getOutputStream();

while(i!=-1)
{
i=fis.read();
os.write (i);

}
os.flush();
RequestDispatcher rd;
rd=request.getRequestDispatcher("/FileUpload1");
rd.forward(request, response);

}
catch(Exception ee)
{
System.out.println("error in UploadServlet :"+ee.getMessage());
}
}

}


2nd Servlet :

import java.io.FileOutputStream;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class UploadServlet1 extends HttpServlet

{

public void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{

try
{

FileOutputStream fos=new FileOutputStream("C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/uploads/sample1.txt");

ServletInputStream instream = request.getInputStream();
int i=0;
System.out.println("in UploadServlet1");
while(i!=-1)
{
i=instream.read();
System.out.println("i is"+i);

fos.write(i);
}




}
catch(Exception ee)
{
System.out.println("error in UploadServlet1:"+ee.getMessage());
}
}
}

Please Help me...............................