try this code as it is working fine with me
String argString = "string you want to send";
URL url = new URL("");
//url of second servlet where you want to send http
req.
URLConnection con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
//write the arguments as post data
DataOutputStream out = new
DataOutputStream(con.getOutputStream());
out.writeBytes(argString);
BufferedReader bf = new BufferedReader(new
InputStreamReader(con.getInputStream()));
String temp=null;
while((temp=bf.readLine())!= null){
System.out.println(temp);
}
Any clarification revert back,
Regards,
Suresh
--- lamph <[EMAIL PROTECTED]> wrote:
> Salut!
>
> I think you need to do an url.setDoInput(true) to
> fix the problem. The
> javadoc of URLConnection says:
>
> "A URL connection can be used for input and/or
> output. Set the DoInput flag
> to true if you intend to use
> the URL connection for input, false if not. The
> default is true unless
> DoOutput is explicitly set to true, in
> which case DoInput defaults to false."
>
> Since you do set the DoOutput flag to true its
> normal to get an exception.
>
> When you try to get the InputStream it is supposed
> to throw you an
> IOException. FileNotFoundException is an
> IOException but it's kinda strange
> to throw that particular one from an URLConnection
> !!!!
>
>
> Hope this helps,
>
> Philippe Lamy
> TouchTunes Digital Jukebox
>
>
>
>
> Stephane Cloutier wrote:
>
> > I hope somebody could explain me this weird
> problem... I have a servlet who
> > must send requests to another servlet. I choose
> to do this with an
> > URLConnection object. I create an OutputStream
> and write my parameters and
> > values into it. After that, I create an
> InputStream to read the return
> > page (I didn't really need to read the page but it
> seems necessary to get
> > done the redirection that is performed at the end
> of the second request
> > call). This was working with servletrunner of
> jsdk2.0 but it doesn't work
> > with JRun and resin that I actually use. It throw
> a FileNotFoundException
> > on the second servlet URL when getting the
> inputstream!?
> >
> > I seriously think to do this with
> RequestDispatcher, but I'll be very happy
> > to be enlighten on this since I don't understand
> why a file exception for a
> > url?? Below is the code I use to make the
> communication between the 2
> > servlets...
> >
> > Thanks,
> > Stephane Cloutier
> >
> > URLConnection url = servlet.openConnection();
> > url.setDoOutput(true);
> > PrintWriter out = new
> PrintWriter(url.getOutputStream());
> > out.print("parameter1=value1");
> > out.print("parameter2=value2");
> > out.print("parameterX=valueX");
> > out.close();
> >
> > InputStream istream = null;
> > try
> > {
> > istream = url.getInputStream();
> > }
> > catch(Exception e)
> > {
> > e.printStackTrace();
> > }
> > InputStreamReader ireader = new
> InputStreamReader(istream);
> > BufferedReader in = new BufferedReader(new
> > InputStreamReader(url.getInputStream()));
> >
> > String inputLine;
> > while ((inputLine = in.readLine()) != null)
> System.out.println(inputLine);
> > in.close();
> >
> >
>
___________________________________________________________________________
> > 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
>
>
___________________________________________________________________________
> 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
__________________________________________________
Do You Yahoo!?
Send instant messages with Yahoo! Messenger.
http://im.yahoo.com/
___________________________________________________________________________
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