URL url=new URL(urlString);
//urlString好像不能带参数,比如urlString="http://192.168.1.186/index.jsp?flag=1",参数flag=1传不过去,请问如何解决

解决方案 »

  1.   

    I don't konw, but please show me the error message...
      

  2.   

    Firstly, "." and "?" need escape character...
      

  3.   

    我试了一下..可以传过去啊..你试着把你URL url=new URL(urlString);这个的 url打印出来你就能看到了.  我打印出来是 完整的..有参数.
      

  4.   


    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,然后保存到数据库里,请问大家有没有什么好的办法.
      

  5.   

    用不用第三方jar  HttpClient
    http://www.ibm.com/developerworks/cn/opensource/os-httpclient/
    直接给参数就行