Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

URL Connection

843841Sep 6 2005
Hi,

I have a problem.
The problem is that i want to pass the parameter from the java class to a servlet. Hence i am using URLConnection object

When was trying with only sending parameter i.e. having
setDoOutput(true);
setDoInput(false);
, the servlet was not getting called.

And when i tried with setDoInput(true); and using an InputStream object it gives me an error:

java.io.IOException: Server returned HTTP response code: 500 for URL: http://192.168.0.63:8080/Examples/TestServlet
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
String myUrl = "http://192.168.0.63:8080/Examples/TestServlet";
System.out.println("Url : "+myUrl);
URL u = new URL(myUrl);
URLConnection uc = u.openConnection();
System.out.println("URLConnection");
uc.setDoOutput(true);
System.out.println("setDoOutput");
uc.connect();
System.out.println("connect");
OutputStream out = uc.getOutputStream();
System.out.println("OutputStream");
System.out.println("Data is : "+"action=performtask&message="+Data).toString());
out.write(("action=performtask&message="+Data).getBytes());
InputStream stream = uc.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
int i = 0;
while ((i = in.read()) != -1) {
System.out.write(i);
 }
 in.close();
out.close();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2005
Added on Sep 6 2005
0 comments
189 views