How to ignnore some websites

I m storing links in vectors and then i vist each link to find out more links

sometimes a page requires a user to enter something hence i get the below exception

java.io.IOException: Server returned HTTP response code


How do i skip out these pages ? either by not storing them in the first place or if encoutered such a page skip it and move on to the next link in the vector
rimmer0007Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GrandSchtroumpfConnect With a Mentor Commented:
just catch the exception and take appropriate action.
0
 
rimmer0007Author Commented:
somthing like this

HTTP_UNAUTHORIZED =401;
http = (HttpURLConnection) url.openConnection();
                        
if(http.getResponseCode()== HTTP_UNAUTHORIZED )
{
      //move onto next link in vector                        
}
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
CEHJConnect With a Mentor Commented:
Exactly. You don't need to define the constant - it's already defined:

if (http.getResponseCode()== HttpURLConnection.HTTP_UNAUTHORIZED )
0
 
objectsCommented:
you need to catch the exception anyway (to handle other failure cases).

for each link
{
   try
   {
      // attempt connection
   }
   catch (Exception ex)
   {
      // error occurred
   }
}
 
0
 
CEHJCommented:
You need to combine both techniques for proper control
0
 
objectsCommented:
not necessarily, plus there are *lots* of other response codes that also need to be handled.
0
 
rimmer0007Author Commented:
are there any quick ways of handling the other responses or am i going to have set up lots of if statements ?
0
 
objectsCommented:
a try/catch as suggested above should pick up many of them.
or perhaps just test for successful response code and treat everything else as failure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.