java - 如何使用带有 java 类值的 JSP 获取动态 href 标记

标签 java jquery html jsp

我现在可以动态获取 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 中访问我的 map 中的值,有什么错误吗?

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());
//        }
    }

最佳答案

你需要使用表达式标签 href="<%=tc%>"

如果您在 tc 中获得正确的路径。

希望对您有所帮助。

关于java - 如何使用带有 java 类值的 JSP 获取动态 href 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41950447/

相关文章:

java - 结合 shiro :hasPermission tags

javascript - jquery click 事件不会在使用 jquery 动态创建的元素上触发

javascript - 当我将鼠标悬停在 iframe 上时,DIV 会闪烁

jquery - 在缩略图上显示鼠标上的链接图像

python - 使用python将图像输出到html

java - 此 Sonar 规则未触发

java - 替换片段时解析 thymeleaf 模板时出错

java - 打印HashMaps : Map. Entry或java8的HashMap

jquery - 想要在单击删除 anchor 标记时删除相应行

javascript - 使用select过滤表数据的问题