/**
@version 1.10 2004-08-04
@author Cay Horstmann
*/
import java.io.*;
import java.net.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This program demonstrates how to use the URLConnection class for a POST
* request.
*/
public class PostTest {
public static void main(String[] args) {
JFrame frame = new PostTestFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class PostTestFrame extends JFrame {
/**
* Makes a POST request and returns the server response.
*
* @param urlString
* the URL to post to
* .
* @return the server reply (either from the input stream or the error
* stream)
*/
public static String doPost(String urlString
) throws IOException {
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
// 设置连接可以写出
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.print("tbl=001");
out.print("&cty="+countries[2 * combo.getSelectedIndex() + 1]);
out.print("&optyr="+URLEncoder.encode("latest checked", "UTF-8"));
out.close();
Scanner in;
StringBuilder response = new StringBuilder();
try {
in = new Scanner(connection.getInputStream());
} catch (IOException e) {
if (!(connection instanceof HttpURLConnection))
throw e;
InputStream err = ((HttpURLConnection) connection).getErrorStream();
if (err == null)
throw e;
in = new Scanner(err);
}
while (in.hasNextLine()) {
response.append(in.nextLine());
response.append("\n");
}
in.close();
return response.toString();
}
public PostTestFrame() {
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setTitle("PostTest");
JPanel northPanel = new JPanel();
add(northPanel, BorderLayout.NORTH);
combo = new JComboBox();
for (int i = 0; i < countries.length; i += 2)
combo.addItem(countries[i]);
northPanel.add(combo);
final JTextArea result = new JTextArea();
add(new JScrollPane(result));
JButton getButton = new JButton("Get");
northPanel.add(getButton);
getButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
result.setText("");
try {
result.setText(doPost(SERVER_URL));
} catch (IOException e) {
result.setText("" + e);
}
}
});
}
static final String SERVER_URL = "http://www.census.gov/cgi-bin/ipc/idbsprd";
public static final int DEFAULT_WIDTH = 400;
public static final int DEFAULT_HEIGHT = 300;
static JComboBox combo;
private static String[] countries = { "Afghanistan", "AF", "Albania", "AL",
"Algeria", "AG", "American Samoa", "AQ", "Andorra", "AN", "Angola",
"AO", "Anguilla", "AV", "Antigua and Barbuda", "AC", "Argentina",
"AR", "Armenia", "AM", "Aruba", "AA", "Australia", "AS", "Austria",
"AU", "Azerbaijan", "AJ", "Bahamas, The", "BF", "Bahrain", "BA",
"Bangladesh", "BG", "Barbados", "BB", "Belarus", "BO", "Belgium",
"BE", "Belize", "BH", "Benin", "BN", "Bermuda", "BD", "Bhutan",
"BT", "Bolivia", "BL", "Bosnia and Herzegovina", "BK", "Botswana",
"BC", "Brazil", "BR", "Brunei", "BX", "Bulgaria", "BU",
"Burkina Faso", "UV", "Burma", "BM", "Burundi", "BY", "Cambodia",
"CB", "Cameroon", "CM", "Canada", "CA", "Cape Verde", "CV",
"Cayman Islands", "CJ", "Central African Republic", "CT", "Chad",
"CD", "Chile", "CI", "China", "CH", "Colombia", "CO", "Comoros",
"CN", "Congo (Brazzaville", "CF", "Congo (Kinshasa)", "CG",
"Cook Islands", "CW", "Costa Rica", "CS", "Cote d'Ivoire", "IV",
"Croatia", "HR", "Cuba", "CU", "Cyprus", "CY", "Czech Republic",
"EZ", "Denmark", "DA", "Djibouti", "DJ", "Dominica", "DO",
"Dominican Republic", "DR", "East Timor", "TT", "Ecuador", "EC",
"Egypt", "EG", "El Salvador", "ES", "Equatorial Guinea", "EK",
"Eritrea", "ER", "Estonia", "EN", "Ethiopia", "ET",
"Faroe Islands", "FO", "Fiji", "FJ", "Finland", "FI", "France",
"FR", "French Guiana", "FG", "French Polynesia", "FP", "Gabon",
"GB", "Gambia, The", "GA", "Gaza Strip", "GZ", "Georgia", "GG",
"Germany", "GM", "Ghana", "GH", "Gibraltar", "GI", "Greece", "GR",
"Greenland", "GL", "Grenada", "GJ", "Guadeloupe", "GP", "Guam",
"GQ", "Guatemala", "GT", "Guernsey", "GK", "Guinea", "GV",
"Guinea-Bissau", "PU", "Guyana", "GY", "Haiti", "HA", "Honduras",
"HO", "Hong Kong S.A.R", "HK", "Hungary", "HU", "Iceland", "IC",
"India", "IN", "Indonesia", "ID", "Iran", "IR", "Iraq", "IZ",
"Ireland", "EI", "Israel", "IS", "Italy", "IT", "Jamaica", "JM",
"Japan", "JA", "Jersey", "JE", "Jordan", "JO", "Kazakhstan", "KZ",
"Kenya", "KE", "Kiribati", "KR", "Korea, North", "KN",
"Korea, South", "KS", "Kuwait", "KU", "Kyrgyzstan", "KG", "Laos",
"LA", "Latvia", "LG", "Lebanon", "LE", "Lesotho", "LT", "Liberia",
"LI", "Libya", "LY", "Liechtenstein", "LS", "Lithuania", "LH",
"Luxembourg", "LU", "Macau S.A.R", "MC",
"Macedonia, The Former Yugo. Rep. of", "MK", "Madagascar", "MA",
"Malawi", "MI", "Malaysia", "MY", "Maldives", "MV", "Mali", "ML",
"Malta", "MT", "Man, Isle of", "IM", "Marshall Islands", "RM",
"Martinique", "MB", "Mauritania", "MR", "Mauritius", "MP",
"Mayotte", "MF", "Mexico", "MX", "Micronesia, Federated States of",
"FM", "Moldova", "MD", "Monaco", "MN", "Mongolia", "MG",
"Montserrat", "MH", "Morocco", "MO", "Mozambique", "MZ", "Namibia",
"WA", "Nauru", "NR", "Nepal", "NP", "Netherlands", "NL",
"Netherlands Antilles", "NT", "New Caledonia", "NC", "New Zealand",
"NZ", "Nicaragua", "NU", "Niger", "NG", "Nigeria", "NI",
"Northern Mariana Islands", "CQ", "Norway", "NO", "Oman", "MU",
"Pakistan", "PK", "Palau", "PS", "Panama", "PM",
"Papua New Guinea", "PP", "Paraguay", "PA", "Peru", "PE",
"Philippines", "RP", "Poland", "PL", "Portugal", "PO",
"Puerto Rico", "RQ", "Qatar", "QA", "Reunion", "RE", "Romania",
"RO", "Russia", "RS", "Rwanda", "RW", "Saint Helena", "SH",
"Saint Kitts and Nevis", "SC", "Saint Lucia", "ST",
"Saint Pierre and Miquelon", "SB",
"Saint Vincent and the Grenadines", "VC", "Samoa", "WS",
"San Marino", "SM", "Sao Tome and Principe", "TP", "Saudi Arabia",
"SA", "Senegal", "SG", "Serbia and Montenegro", "YI", "Seychelles",
"SE", "Sierra Leone", "SL", "Singapore", "SN", "Slovakia", "LO",
"Slovenia", "SI", "Solomon Islands", "BP", "Somalia", "SO",
"South Africa", "SF", "Spain", "SP", "Sri Lanka", "CE", "Sudan",
"SU", "Suriname", "NS", "Swaziland", "WZ", "Sweden", "SW",
"Switzerland", "SZ", "Syria", "SY", "Taiwan", "TW", "Tajikistan",
"TI", "Tanzania", "TZ", "Thailand", "TH", "Togo", "TO", "Tonga",
"TN", "Trinidad and Tobago", "TD", "Tunisia", "TS", "Turkey", "TU",
"Turkmenistan", "TX", "Turks and Caicos Islands", "TK", "Tuvalu",
"TV", "Uganda", "UG", "Ukraine", "UP", "United Arab Emirates",
"TC", "United Kingdom", "UK", "United States", "US", "Uruguay",
"UY", "Uzbekistan", "UZ", "Vanuatu", "NH", "Venezuela", "VE",
"Vietnam", "VM", "Virgin Islands", "VQ", "Virgin Islands, British",
"VI", "Wallis and Futuna", "WF", "West Bank", "WE",
"Western Sahara", "WI", "Yemen", "YM", "Zambia", "ZA", "Zimbabwe",
"ZI" };
}
没有合适的资源?快使用搜索试试~ 我知道了~
java基础(多线程,IO,集合,网络编程,泛型)
共173个文件
class:94个
java:63个
ppt:5个
5星 · 超过95%的资源 需积分: 11 73 下载量 28 浏览量
2008-10-14
11:34:26
上传
评论
收藏 479KB RAR 举报
温馨提示
一些基础的东西..都是PPT,外带PPT的所有java以及class文件
资源推荐
资源详情
资源评论
收起资源包目录
java基础(多线程,IO,集合,网络编程,泛型) (173个子文件)
PostTestFrame.class 12KB
MovieStore.class 3KB
StudentClass.class 3KB
Student.class 3KB
Unzip.class 2KB
Blip3.class 2KB
MovieStoreTester.class 2KB
SortedIntArray.class 2KB
Tester1.class 2KB
Ex6_18.class 2KB
Philosopher.class 2KB
CopyMaker.class 2KB
NewCopyBytes.class 2KB
Ex6_15.class 2KB
URLConnectionTest.class 2KB
EchoClient.class 2KB
Ex6_14.class 2KB
Ex6_17.class 2KB
EchoServer.class 2KB
EnumerationTester2.class 2KB
CopyingArrays.class 2KB
IteratorTester.class 1KB
CopyBytes.class 1KB
Movie.class 1KB
TableTester.class 1KB
Ex6_8.class 1KB
Redirecting.class 1KB
Ex6_11.class 1KB
SortTester.class 1KB
ListOfFiles.class 1KB
CompType.class 1KB
EchoSquare.class 1KB
Ex6_9.class 1KB
Ex6_10.class 1KB
Ex6_7.class 1KB
BreadContainer.class 1KB
PostTestFrame$1.class 1KB
TestThread4.class 1KB
TestThread3.class 1KB
Ex6_3.class 1KB
Keyboard.class 1KB
Ex6_5.class 1KB
TestThread2.class 1KB
Tickets.class 1KB
EnumerationTester.class 1KB
Consumer.class 1KB
InetAddressTest.class 1KB
Ex6_13.class 1015B
Tickets.class 993B
SellTickets.class 983B
ComparingArrays.class 928B
FactorialThread.class 921B
FactorialThread1.class 913B
Producer.class 913B
Consumer.class 910B
Ex8_4.class 886B
Ex6_4.class 882B
TestThread1.class 862B
Ex6_16.class 855B
Concatenate.class 843B
Producer.class 839B
Ex8_5.class 824B
Ex6_2.class 787B
Ex8_11.class 782B
Ex8_2.class 764B
Ex6_12.class 759B
Ex8_3.class 758B
Chopstick.class 741B
DiningPhilosophers.class 739B
Bread.class 733B
Baker.class 721B
Buyer.class 693B
Ex8_1.class 677B
MakeAndBuyBread.class 669B
Employee.class 652B
Ex6_6.class 643B
ChangeSystemOut.class 636B
Ex8_12.class 615B
TestThread.class 601B
Ex8_7.class 588B
Ex8_9.class 581B
Ex8_8.class 581B
PostTest.class 560B
Ex8_6.class 543B
Ex8_7.class 539B
Consumer.class 529B
Producer.class 528B
Producer.class 528B
Consumer.class 524B
Book.class 522B
Ex8_10.class 487B
Tickets.class 396B
Tickets.class 382B
ThreadTest.class 316B
.classpath 226B
.classpath 226B
.classpath 226B
.classpath 226B
mixedTypes.dat 22B
PostTest.java 7KB
共 173 条
- 1
- 2
资源评论
- 韩非歌浩2015-10-28学习了,不过ppt配色真是伤眼睛
- l_dongdong2014-08-14不错,基础的学习资料
- janrn2013-11-05PPT不怎么样
- 码农先生2013-09-15还行吧,PPT不怎么样
- derekrose2012-07-19学习了,还有源码挺不错的
xiao56763619
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功