我正在尝试向 Arraylist
添加 href,这很好地添加到 Arraylist
,但链接已损坏。 URL 中问号 (?) 后面的所有内容均不包含在链接中。
有什么我遗漏的吗,代码如下:
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;
}
最佳答案
您遇到 "
围绕 unid
值转义的问题,导致您的 URL 变成 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));
关于java - Xpages - 在 Arraylist 中传递 <ahref>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55000855/