• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

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
0
rimmer0007
Asked:
rimmer0007
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
GrandSchtroumpfCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now