简体   繁体   中英

How to print a link by System.out.println

I'd like to print the HTML link in Eclipse console by using System.out.println .

When I use System.out.println("<a href=\\"http://www.google.com\\">whatever</a>") ;

it prints the string and not a link that I can click on.


Edit
I'm creating JUnit HTML report using Ant. It contains all output created by System.out.println in the browser. I want to pass a link constructed from within a program.

You are printing to the standard output stream. If you can't click on the the printed HTML link, it means the standard output of your system does not support HTML and treats it as a string. (usually it just displays on the screen)

Up to now, I do not know about a system, which could have the standard output with such a feature. See: https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#out

Eclipse console has no support for it, but maybe you can write a plugin.

EDIT:

JUnit HTML report will take the output and convert the string to HTML entities and wrap into the PRE tag to ensure it is displayed in the same way as it was on the console. I'm not sure if you can modify this behaviour without extending the JUnit ant task source code.

如果你真的需要做“这个.. ”,你可以使用JEdi​​torPane .. 和一些 GUI.. 但可以肯定的是,你的控制台永远无法做这样的事情..

Use URL. You can do

URL myURL = new URL("http://example.com/");

Then just

System.out.println(myURL);

This will output your URL and not "myURL"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM