Solved

How to ignnore some websites

Posted on 2004-08-01
10
174 Views
Last Modified: 2012-05-05
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
Comment
Question by:rimmer0007
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 200 total points
ID: 11689013
just catch the exception and take appropriate action.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 11689021
0
 

Author Comment

by:rimmer0007
ID: 11689110
somthing like this

HTTP_UNAUTHORIZED =401;
http = (HttpURLConnection) url.openConnection();
                        
if(http.getResponseCode()== HTTP_UNAUTHORIZED )
{
      //move onto next link in vector                        
}
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 11689224
Exactly. You don't need to define the constant - it's already defined:

if (http.getResponseCode()== HttpURLConnection.HTTP_UNAUTHORIZED )
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 92

Expert Comment

by:objects
ID: 11689729
you need to catch the exception anyway (to handle other failure cases).

for each link
{
   try
   {
      // attempt connection
   }
   catch (Exception ex)
   {
      // error occurred
   }
}
 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11689737
You need to combine both techniques for proper control
0
 
LVL 92

Expert Comment

by:objects
ID: 11689752
not necessarily, plus there are *lots* of other response codes that also need to be handled.
0
 

Author Comment

by:rimmer0007
ID: 11704848
are there any quick ways of handling the other responses or am i going to have set up lots of if statements ?
0
 
LVL 92

Expert Comment

by:objects
ID: 11710722
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now