2013-03-02 41 views

回答

2

以上不能編譯。如果您沒有嘗試將所有內容放在同一行上,您將會理解爲什麼更容易

首先爲System.getProperty("...")創建變量。然後每行放一條指令。那麼不要混合使用append()+級聯運算符。代碼變爲:

String host = System.getProperty("application.middleware.webapplication.host"); 
content.append("<a href=\""); 
content.append(host); 
content.append(":")"/"/">); 

而最後一條指令無效。要成爲有效的,使一個鏈接,你會需要像

String host = System.getProperty("application.middleware.webapplication.host"); 
content.append("<a href=\""); 
content.append(host); 
content.append("\">Click here</a>"); 

尊重的Java命名約定(變量以小寫字母)也使代碼易於閱讀和理解的關鍵。

4

什麼有關這樣簡單的解決方案?

String host = System.getProperty("application.middleware.webapplication.host"); 
String url = "http://" + host; 
String linkText = "please click here"; 
Content.append("<a href='"+ url + "'>" + linkText + "</a>"); 
1
Content.append("<a href=\"") 
     .append(System.getProperty("application.middleware.webapplication.host")) 
     .append("\">My Link</a>");