URL url=new URL(urlString);
//urlString好像不能带参数,比如urlString="http://192.168.1.186/index.jsp?flag=1",参数flag=1传不过去,请问如何解决
解决方案 »
- 关于《Java2核心技术卷I》一书中的小问题
- 请教:测试方面的问题
- 监测按键问题
- [连接池中]关于connection.colse()的疑问!
- 未装jre情况下,怎么做.jar包?
- write in text file
- 怎样在java中断定一个文件的文件类型???(高分)
- 请问学JavaSE有什么好书推荐吗?
- 急!高手请进,救命啊
- 在VJ++6.0的环境下,当编译时,出现"Unable to update resources in file:'d:\visual Studio projects\cy1\server\server.exe". 如何解决?
- 如何用Runtime.getRuntime().exec来打开某个压缩文件,并解压到指定位置?
- java中读文件的时候能不能忽略空格啊?
import java.net.*;
import java.io.*;
import java.util.*;
public class TestURL {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:9999/cms/cms/website/test3/index.jsp?siteId=11");
URLConnection urlcon = url.openConnection();
System.out.println("UrlContent TimeOut:"+urlcon.getConnectTimeout());
System.out.println("UrlContent LastModified:"+new Date(urlcon.getLastModified()));
int i = urlcon.getContentLength();
byte[] b=new byte[99999];
System.out.println(i);
File file=new File("d:\\test.html");
FileOutputStream writer=new FileOutputStream(file);
if(i>0){
InputStream is = urlcon.getInputStream();
is.read(b);
writer.write(b);
is.close();
writer.flush();
writer.close();
}else{
System.out.println("Length is null.");
}
}}上面是将url中的内容转换为本地的html我试了一下,url中需要传递参数的都不成功,不需要传递参数的都可以.我现在有一个jsp的页面,需要转成html,然后保存到数据库里,请问大家有没有什么好的办法.
http://www.ibm.com/developerworks/cn/opensource/os-httpclient/
直接给参数就行