Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

all.

I'm testing my java code for getting weather data from a PHP web page(http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009).

My code runs well on my computer (win7, jre6 and jre7). When I access the above link in the web browser (explorer9, chrome), but the browsers download the 'getFAWNDailyData.php' page itself, not running it.

My problem is that the code did not work on other computer with similar specification (win7, jre6 and jre7). The code tried to read the php page source itself, not data generated by the page. And, its web browsers (explorer9, chrome) also download the page itself like mine.

I could not find any difference between two computers, and could not generate the error at other computers.

Could you give any clue which I could check out?

Here is my code;

try {
    url = new URL(
            "http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009");

    URLConnection urlConn = url.openConnection();

    InputStream is = urlConn.getInputStream();
    InputStreamReader reader = new InputStreamReader(is);
    BufferedReader bf = new BufferedReader(reader);

    int lines = 0;
    int wind_count = 0, airtemp_count = 0;

    // et starts from the 2nd line
    String firstLine = bf.readLine(); // firstLine is "DATETIME,ET"
    System.out.print("\n" + "-----" + firstLine + "\n");

    String year = "", month = "", day = "", WindCount = "", AirTempCount = "";
    int monthNum = 0;
    String line = bf.readLine();
    System.out.print("\n" + "-----" + line + "\n");

    StringTokenizer st = new StringTokenizer(line, ",");
    if (st.hasMoreTokens()) {
        year = st.nextToken();
    }
    if (st.hasMoreTokens()) {
        month = st.nextToken();
        String[] values = month.split(" ");
        day = values[0].substring(1);
        year = values[2].replace('"', ' ');
        year = year.trim();
        month = values[1].trim();
        monthNum = getMonthValue(month);
    }

    System.out.println("year---:[" + year + "]");
    System.out.println("month---:[" + month + "]");
    System.out.println("day---:[" + day + "]");
} catch (MalformedURLException me) {
    me.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (is != null)
        try {
            is.close();
        } catch (IOException e) {
            ;
        }
}

Thanks.

share|improve this question
 
what do you mean by "The code tried to read the php page source itself, not data generated by the page", what did the error/output/etc look like? –  Peter Elliott Jan 16 at 1:41
 
php code was downloaded, not getting data generate by the php page. –  yun Jan 16 at 1:57
 
output of year was second line of php code like below; <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> –  yun Jan 16 at 1:58

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.