Results 1 to 4 of 4
  1. #1
    achab is offline Member
    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0

    Default Could you tell me how to fix the offending 3 lines try block

    First, here is the offending program. The 3 lines offending try block are in Bold, Italic and Underlined.

    Java Code:
    import java.io.*;
    import java.util.*;
    import java.net.*;
    
    public class WebScanner {
        public static void main(String args[]) {
            scanAssessorsWebSite();
            scanTreasurersWebSite();
        }
    
        private static void scanAssessorsWebSite() {   // WORKS !!!
            try {
                URL taxIDURL = new URL("http://www.maricopa.gov/assessor/ParcelApplication/Detail.aspx?ID=101-01-663");
                URLConnection conn = taxIDURL.openConnection();
                DataInputStream data = new DataInputStream(new  BufferedInputStream(conn.getInputStream()));
                System.out.println("tID = ");
    
            }
            catch (MalformedURLException e) {
                System.out.println("Malformed URL: http://www.maricopa.gov/assessor/ParcelApplication/Detail.aspx?ID=101-01-663");
    // _webAccessFailed = false;
            }
            catch (IOException e) {
                System.out.println("Open Stream Exception");
            }
        }
    
        private static void scanTreasurersWebSite() {   // DOESN'T WORK !
            String line = new String();
            try {
       [B][I][U]         URL taxIDURL = new URL("http://treasurer.maricopa.gov/parcels/default.asp?Parcel=10101663");
                URLConnection conn = taxIDURL.openConnection();
                DataInputStream data = new DataInputStream(new BufferedInputStream(conn.getInputStream()));[/U][/I][/B]
            }
            catch (MalformedURLException e) {
                System.out.println("Malformed URL: http://treasurer.maricopa.gov/parcels/default.asp?Parcel=10101663");
            }
            catch (IOException e) {
                System.out.println("scanTreasurersWebSite - Caugh Exception " + e.toString());
            }
        }
    }


    End of WebScanner.java



    Second, the output:



    tID =
    scanTreasurersWebSite - Caugh Exception java.io.IOException: Server returned HTTP response code: 400 for URL: http://
    treasurer.maricopa.gov/Parcel/SetSession.asp?pn=10101663&tcd=1&fpn=101-01-663 1&mry=2010&sec=True&rf=False&dp=S



    End of Output




    Third, some comments about the difference in the 2 web sites I am trying to read (the successful try, and the unsuccessful one):


    The page I succeeded in reading is
    http://www.maricopa.gov/assessor/Par...?ID=101-01-663
    If you typed that URL in your browser and hit enter, you will still see that URL in your browser.

    The one I am unable to read is:
    treasurer.maricopa.gov/parcels/default.asp?Parcel=10101663
    If you typed that URL in your browser and hit enter, you will see the following URL in your browser: treasurer.maricopa.gov/Parcel/Summary.aspx

    I suspect this type of redirection is causing problems for my code.




    Last but not least, the plea: please reply in Java code, ideally a new try block that in some way loads the data from the Treasurer's web page, and not in Shakespearean verbiage as in "to be or not to be, that's the question", or "what you need to do is fork a semaphore that will open the URL's socket using the TPC protocol to get around the apache deamon". I have no idea how to compile and run either of the 2 previous statements.

    Thanks,

    Abdenour
    Last edited by achab; 11-01-2010 at 07:38 PM. Reason: moderator edit: code tags added

  2. #2
    wjncross is offline Member
    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    Default

    Place the URL that is creating the exception in to your browser and look at the response! You will probably see that it causes an error code of 400+ (client request error)

    The URL is bad and that is why you get the error. If you look at the URL you say you want further down the thread it is not the same as the one you are requesting.

    The one you want does not contain all the "....1&mry=2010&sec=True&rf=False&dp=S" parameters.

    I don't think you are far short of having what you want if part of your code is working (not looked at is fully). The problem is down to the URL you are requesting.

  3. #3
    achab is offline Member
    Join Date
    Nov 2010
    Posts
    26
    Rep Power
    0

    Default

    Thanks WJN Cross for your reply. The URL I am trying to read from the code is:
    treasurer.maricopa.gov/parcels/default.asp?Parcel=10101663

    If you place it in your browser, you will see that it's a valid URL. I don't know why the URL that shows up in the exception message has the extra stuff that I did not put in the code.

    An alternative to fix my problem is for me to be able to write 10101663 to
    treasurer.maricopa.gov/Parcel/Summary.aspx

    If you type treasurer.maricopa.gov/Parcel/Summary.aspx in a different browser or computer (to avoid the cache), you will see a text field where I can enter that. I haven't succeeded in doing that from code yet. I will post the code later on this forum, once I have given up trying to solve it on my own.

    Abdenour
    Last edited by achab; 11-02-2010 at 06:53 AM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Debug the code and see what value url has before opening it.

    Also, when catching exceptions, at the very least printStackTrace().

Similar Threads

  1. block url
    By thedevilz in forum New To Java
    Replies: 1
    Last Post: 09-16-2010, 10:55 PM
  2. if block with logical or
    By Ranu in forum New To Java
    Replies: 6
    Last Post: 07-01-2010, 08:11 AM
  3. Someone plz help... how to block inputs
    By waklo99 in forum New To Java
    Replies: 4
    Last Post: 03-15-2010, 06:44 AM
  4. Try/catch block
    By swati.jyoti in forum New To Java
    Replies: 5
    Last Post: 07-02-2009, 02:32 PM
  5. Return to try block
    By Freddie in forum New To Java
    Replies: 2
    Last Post: 05-11-2007, 08:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •