Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to detect the web page is available or not?????

Posted on 2002-06-10
8
Medium Priority
?
212 Views
Last Modified: 2010-03-31
Hi:
   Here I have a question about java. Fot the program to open an web page, before is open it, it must chekc the page can be opened ot not. I use getContentLength() to get the size, if it is < 0 then treat it as unrreachable, otherwise use .showdocument (url,) to open it. It work in the case of the auto directed program and the destination page at the same server. If ther are in different sever, it return size <0 but the ppage is available. Can anybody give idea why it like this.
   Or maybe there has other way to do it???
   Millions of thanks in advance!!

Best Regard

0
Comment
Question by:wky086
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 7066567
the http response code must be 404 when the page is not present
0
 

Author Comment

by:wky086
ID: 7067357
Sorry , but which method in java is used to get the error code?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7068044
You can't rely on getContentLength() to give you the correct data. You *could* send a HEAD request first, but why not do a GET right away? The only rationale I can think of for checking first is if you expect the majority of requests to fail.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:wky086
ID: 7137033
But How to use Get to send the request. Sorry I have not idea about it. Can you give me some hint in code. in html or javascript is OK.
I test with this code
try {
URL url =new URL(URLName);

URLConnection urlconn = url.openConnection();
urlconn.connect();
HttpURLConnection httpconn =(HttpURLConnection)urlconn;
HttpResult = httpconn.getResponseCode();
if(HttpResult == HttpURLConnection.HTTP_OK)
....
}
catch (){
}
it catch exception. Do you have any idea about this code
Millions of thanks in advance
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7137060
URL url =new URL(URLName);
HttpURLConnection urlconn = (HttpURLConnection)urlconn.setRequestMethod("GET");
url.openConnection();
...
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 200 total points
ID: 7137061
regarding the response code - use
urlconn.setResponseCode(); method of the HttpUrlConnection object
0
 
LVL 35

Expert Comment

by:girionis
ID: 8834318
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to Venci75

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8838963
Of course, correct operation of Venci75's suggestion relies on correct server behaviour, which is an assumption you can't make IMHO. A better way would be to open an input stream on the URLConnection.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question