jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes How to check whether urlconnection is active? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to check whether urlconnection is active?" Watch "How to check whether urlconnection is active?" New topic
Author

How to check whether urlconnection is active?

subha neithilath
Greenhorn

Joined: Nov 10, 2002
Posts: 4
Hi,
I am calling a servlet residing in a domino server from a java program.I am passing a cookie value but servlet is not getting invoked.I would like to know how i can test whether the connection is active or not(can you suggest any programs that i can use for testing the same)
I am providing here few lines of code which i am using to get urlconnection and set cookie.
HttpURLConnection urlconnection = null;
URL serverURL = new URL("http://192.168.10.55:8001/servlet/testing");
urlconnection= (HttpURLConnection)serverURL.openConnection();
urlconnection.setRequestProperty("cookie",cookie);
urlconnection.setRequestMethod("GET");
urlconnection.setFollowRedirects(true);
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
Please go through and give suggestion/sample programs
Thanks and Regards
Subha
Mohamed Yousuff
Ranch Hand

Joined: Jun 23, 2001
Posts: 73
Your code is fine to some extent. I dont really understand what you really mean by 'connection is active or not'. If the openConnection method is successfull (without exception), it definitely means that the connection to the server is established. If the servlet does not get invoked, it indicates invalid usage of HTTP Protocol. If you use setdooutput(true) and setdoinput(true), you need to get the outputstream of the httpurlconnection and write whatever you want to write to it. Then u need to get the inputstream.
Also when you use setdooutput(true), setrequestmethod("GET") does not make sense because setdooutput(true) implicitly means you want POST method.

Originally posted by subha neithilath:
Hi,
I am calling a servlet residing in a domino server from a java program.I am passing a cookie value but servlet is not getting invoked.I would like to know how i can test whether the connection is active or not(can you suggest any programs that i can use for testing the same)
I am providing here few lines of code which i am using to get urlconnection and set cookie.
HttpURLConnection urlconnection = null;
URL serverURL = new URL("http://192.168.10.55:8001/servlet/testing");
urlconnection= (HttpURLConnection)serverURL.openConnection();
urlconnection.setRequestProperty("cookie",cookie);
urlconnection.setRequestMethod("GET");
urlconnection.setFollowRedirects(true);
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
Please go through and give suggestion/sample programs
Thanks and Regards
Subha

[ November 11, 2002: Message edited by: Mohamed Yousuff ]
[ November 11, 2002: Message edited by: Mohamed Yousuff ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check whether urlconnection is active?
 
Similar Threads
Use of HttpClient in Applet
Cookies from Servlets sendRedirect
Cookies from Servlets sendRedirect
Applet cookie access and retrieval
server down/up???