如果,想知道如何根据一个url地址实现打开网页的功能,高手、大侠们都出来帮帮忙,小弟新手、、

解决方案 »

  1.   

    这是打开网页的,要保存网页,用流读取写在本地就行
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    public class test
    {  public static void main(String args[])
       {  new NetWin();
       }
    }
    class NetWin extends JFrame 
    implements ActionListener,Runnable
    {  JButton button;
       URL url;
       JTextField text;
       JTextArea area; 
       byte b[]=new byte[118];
       Thread thread;
       NetWin()
       {  text=new JTextField(20);
          area=new JTextArea(12,12);
          button=new JButton("确定");
          button.addActionListener(this);
          thread=new Thread(this);
          JPanel p=new JPanel();
          p.add(new JLabel("输入网址:"));
          p.add(text); 
          p.add(button);
          add(area,BorderLayout.CENTER);
          add(p,BorderLayout.NORTH);
          setBounds(60,60,460,300);
          setVisible(true);
          validate();
       }
       public void actionPerformed(ActionEvent e)
       { 
          if(!(thread.isAlive())) 
             thread=new Thread(this);
          try{
               thread.start();
             }
          catch(Exception ee)
             { text.setText("我正在读取"+url);
             }
       }
      public void run()
       {    try {    int n=-1;
                     area.setText(null);
                     url=new URL(text.getText().trim());
                     InputStream in=url.openStream();
                     while((n=in.read(b))!=-1)
                     {   String s=new String(b,0,n);
                         area.append(s);    
                     }
                }
              catch(MalformedURLException e1)
               {     text.setText(""+e1);
                     return;
               }
              catch(IOException e1)
               {     text.setText(""+e1);
                     return;
               }  
       }
    }
      

  2.   

    记得有个JEditorPane可以显示网页.
      

  3.   


    url="http://www.hao123.com"
    jEditorPane.setPage(url);
      

  4.   

    java.net.URL.openStream()
    想这么用就怎么用
      

  5.   

    想知道如何根据一个url地址实现打开网页的功能,?
    指的什么意思呢?
    给一个url地址,实现 打开网页功能,
    是在java中打开网页么?
    如果在jsp中直接+ a href 即可。
    在类中没那么搞过.
      

  6.   


    我的意思是给定一个url  打开这个网页 并把这个网页的源码保存在本地三楼的大侠的代码测试过了,有点问题,就是动态url里面出现 ?&  这类的符号的时候  会报错~~
      

  7.   

    StringBuffer sb=null;
    try {
            // Create a URL for the desired page
            URL url = new URL("http://www.baidu.com/index.html");
        
            // Read all the text returned by the server
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            sb=new StringBuffer();
            
            while ((str = in.readLine()) != null) {
                sb.append(str);
            }
            in.close();     } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        
        System.out.println(sb);