【问题标题】:How do I get a dynamic href tag with JSP with a value from java class如何使用 JSP 获取具有来自 java 类的值的动态 href 标记
【发布时间】:2017-06-16 11:14:48
【问题描述】:

我现在可以动态获取 href 标记,但现在无法从我的 MMTUtil 访问 HashMap,它为 mw 提供了与我的 Key(objectName)g 对应的值无法想到我在JSP 这就是我能走多远

MMTUtil.getDomainComboDocumentationMap().get(objectName);

其中 objectName 是一个键,我需要从中获取值以便它可以在 href 中使用

我尝试过的: 我认为这可能行不通

<%
UMRDocumentationDTO documentationDTO = new UMRDocumentationDTO();
String objectName = documentationDTO.getId().getObjectName();  //getting error here and the debgger goes directly at the end of the page
String tc = MMTUtil.getDomainComboDocumentationMap().get(objectName);
%>

我们可以试试这样的吗?

for (Map.Entry entry : MMTUtil.getDomainDocumentationMap().entrySet()){
        Object documentationLink =  entry.getValue();
}



<td><a href="<%=documentationLink%>" target="_blank"
id="domainName_<s:property value="#rowstatus.index"/>"><s:property
value="domainName" /></a>

我无法在 Jsp 中访问我的地图中的值是否有任何错误?

public class MMTUtil
{

private static Map<String, String> domainDocumentationMap             = null;

static
{
    domainDocumentationMap = new HashMap<String, String>();
    domainComboDocumentationMap =new HashMap<String, String>();
}

public static Map<String, String> getDomainDocumentationMap() {
    return domainDocumentationMap;
}

public static void setDomainDocumentationMap(String objectName, String documentationLink) {
    MMTUtil.domainDocumentationMap.put(objectName, documentationLink);

//        for(Map.Entry entry:MMTUtil.domainDocumentationMap.entrySet()){
//            System.out.println(entry.getKey() + " " + entry.getValue());
//        }
    }

【问题讨论】:

  • 使用 javascript (或 jquery) - 向 webservice / servlet (ajax) 询问值,然后使用 jquery 填写

标签: java jquery html jsp


【解决方案1】:

你需要使用表达式标签href="&lt;%=tc%&gt;"

如果你在 tc 中得到正确的路径。

希望对你有帮助。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 2011-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多