简体   繁体   English

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

[英]How do I get a dynamic href tag with JSP with a value from java class

I'm able to get the href tag dynamic now, but now unable to acccess the HashMap from my MMTUtil which gives mw the value corresponding to my Key(objectName)gUnable to think of any solution I have imported the class in the JSP thats how far I'm able to go我现在能够动态获取 href 标签,但现在无法从我的 MMTUtil 访问 HashMap,这给了 mw 对应于我的 Key(objectName)g 的值无法想到我在 JSP 中导入了类的任何解决方案,就是这样我能走多远

MMTUtil.getDomainComboDocumentationMap().get(objectName);

where objectName is a key and I need to get the value out of it So that it can be used in href其中 objectName 是一个键,我需要从中获取值以便它可以在 href 中使用

What I have tried: I think this might not work我尝试过的:我认为这可能行不通

<%
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);
%>

can we try something like this?我们可以尝试这样的事情吗?

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>

I'm unable to access the Value from my Map in Jsp any error?我无法在 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());
//        }
    }

You need to use expression tag href="<%=tc%>"您需要使用表达式标签href="<%=tc%>"

If you are getting the correct path in tc.如果您在 tc 中获得正确的路径。

I hope it will help you.我希望它会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM