日期:2014-05-17  浏览次数:20749 次

如何获取提交页面源码
我写的一个查询html源码的源码,不过没有查询到目标地址的源码
Java code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author happy
 * 
 */
public class JavaGetResource {
    public static void main(String[] args) {
        String uri = "http://jtk.sptcc.com:8080/servlet?addr=110.120.130.99&hiddentype=index&Card_id=72494857632";
        String resource = getOneHtml(uri);
        System.out.println(resource);
    }

    public static String getOneHtml(String htmlurl) {
        URL url;
        String temp;
        StringBuffer sb = new StringBuffer();
        try {
            url = new URL(htmlurl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url
                    .openStream(), "gbk")); // UTF-8
            while ((temp = in.readLine()) != null) {
                sb.append(temp + "\n");
            }
            in.close();
        } catch (MalformedURLException me) {
            System.out.println("你输入的URL格式有问题!请仔细输入");
            me.getMessage();
            try {
                throw me;
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
            try {
                throw e;
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return sb.toString();
    }

}


// JAVA输出的html源码
Java code


<html>
<head><link rel="stylesheet" type="text/css" href="images/jtk.css">
<!--
description:jtk_query
time:2005.8-2005-12
author:zhu tian wei,zhang jun,yang jun
company:sinocomm ltd.
-->
<title>jtk 上海市公共交通卡网上查询</title>
<meta http-equiv="Content-Type" content="text/html;">
<script type="">

function Ret_new()
{
//location.href("newMember.jsp");
}

function Ret_Vip()
{
//location.href("Vip_index.jsp");
}

function Checkout(){
if (Form1.Card_id.value.length=='11')
        {
    if(Form1.User_name.value==""&&Form1.Pass_word.value=="")
    {
    return true;
    }
    else{
        if(Form1.Pass_word.value!="")
        {
            alert("请输入用户名");
            Form1.User_name.focus();
            return false;
             }
        else if(Form1.User_name.value!="")
        {
            alert("请输入密码");
            Form1.Pass_word.focus();
            return false;
        }
                if(Form1.User_name.value.length<'4')
                {
                    alert("用户名必须输入4位以上");
                    Form1.User_name.focus();
                       return false;
                }

                if(Form1.Pass_word.value.length<'6')
                {
                    alert("密码必须输入6位以上");
                    Form1.Pass_word.focus();
                    return false;
                }
                return true;
    }
}
else
    {
     alert("请填入正确的11位卡号");
     Form1.Card_id.focus();
          return false;
    }
}

function Empty(){
//Form1.User_name.value="";
//Form1.Pass_word.value="";
Form1.Card_id.value="";
//Form1.User_name.focus();
return false;
}
function KeyDo