当前位置: 技术问答>java相关
怎样用方法使页面提交
来源: 互联网 发布时间:2015-04-07
本文导语: 怎样用java语言中的方法使页面提交? | 使用URL类提交到一个页面: try { url = new URL("http://www.csdn.net/logon.asp");//举个例子 connection = url.openConnection(); connection.setDoOutpu...
怎样用java语言中的方法使页面提交?
|
使用URL类提交到一个页面:
try {
url = new URL("http://www.csdn.net/logon.asp");//举个例子
connection = url.openConnection();
connection.setDoOutput(true);//定向输出
ostr = connection.getOutputStream();
DataOutputStream writer = new DataOutputStream(ostr);
writer.writeBytes(fieldName + "=" + fieldValue + "&");
writer.writeBytes(fieldName2 + "=" + fieldValue2);
writer.flush();
writer.close();
istr = connection.getInputStream();//取得提交后返回的流
BufferedReader reader = new BufferedReader(new InputStreamReader(istr));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
try {
url = new URL("http://www.csdn.net/logon.asp");//举个例子
connection = url.openConnection();
connection.setDoOutput(true);//定向输出
ostr = connection.getOutputStream();
DataOutputStream writer = new DataOutputStream(ostr);
writer.writeBytes(fieldName + "=" + fieldValue + "&");
writer.writeBytes(fieldName2 + "=" + fieldValue2);
writer.flush();
writer.close();
istr = connection.getInputStream();//取得提交后返回的流
BufferedReader reader = new BufferedReader(new InputStreamReader(istr));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
|
jsp或servlet中,可以使用dispatch