再有代码在JEditorPane中打开类似www.baidu.com的超链接是,运行没有问题,当换成带参数的超链接时,就会提示路径不存在。感觉处理的时候没有把整个链接当成带参数链接处理。急求达人指点。
现有代码如下:
import java.applet.Applet;import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import net.java.dev.designgridlayout.DesignGridLayout;
public class Hyperlink extends Applet { public Hyperlink(){
  JEditorPane jEditorPane = new JEditorPane();
  jEditorPane.setEditable(false);
  jEditorPane.setContentType("text/html");
  jEditorPane.setText("<html><body><a href=\"http://www.baidu.com/s?wd=李宇春\">baidu</a></body></html>");
  jEditorPane.addHyperlinkListener(new HyperlinkListener() {   public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
     try {
      String command = "explorer.exe "
        + e.getURL().toString();
      Runtime.getRuntime().exec(command);
     } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("connection error");
     }
    }   }  });
  DesignGridLayout layout = new DesignGridLayout(this);
  layout.row().grid().add(jEditorPane);
 }
 

解决方案 »

  1.   

    href=\"http://www.baidu.com/s?wd=李宇春\"这么写的话引号里面都成了字符串了没有参数吧
      

  2.   


    wd=李宇春  wd是变量名,李宇春是值。这样可以直接打开百度关于李宇春的检索结果。
      

  3.   

    貌似应该这么写href="http://www.baidu.com/s?wd=李宇春"
      

  4.   

    那俺就不清楚咯,我在jsp里面写的时候好像都是像我上面说的那样写的没加\,要不你试试我说的那种