我正在尝试向Arraylist
添加href,这很好地添加到了Arraylist
,但是链接断开了。网址中问号(?)之后的所有内容均未包含在链接中。
有什么我想念的吗,代码如下:
private String processUpdate(Database dbCurrent) throws NotesException {
int intCountSuccessful = 0;
View vwLookup = dbCurrent.getView("DocsDistribution");
ArrayList<String> listArray = new ArrayList<String>();
Document doc = vwLookup.getFirstDocument();
while (doc != null) {
String paperDistro = doc.getItemValueString("DistroRecords");
if (paperDistro.equals("")) {
String ref = doc.getItemValueString("ref");
String unid = doc.getUniversalID();
// the link generated when adding to Arraylist is broken
listArray.add("<a href=\"gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=\"+ unid + \"&action=openDocument\">" + ref + "</a>");
}
Document tmppmDoc = vwLookup.getNextDocument(doc);
doc.recycle();
doc = tmppmDoc;
}
Collections.sort(listArray);
String listString = "";
for (String s : listArray) {
listString += s + ", \t";
}
return listString;
}
答案 0 :(得分:3)
您遇到"
转义为unid
值的问题,因此您的网址变成了gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId="+ unid + "&action=openDocument
。
如果您使用String.format()
和单引号来生成a
标签,则会更容易阅读:
listArray.add(String.format(
"<a href='gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=%s&action=openDocument'>%s</a>",
unid, ref));