解释 :
我在 JSP 中有一个包含单词的“java.util.list”。
我在 JSP 中有另一个“java.util.list”,其中包含与每个单词对应的 URL 链接。
我需要在同一个 JSP 页面上显示这些词,点击它们应该打开相应的链接。
以下是我的代码尝试:
<html>
<head>
<style>
.container{color:blue;}
#text{width:50%;}
</style>
</head>
<body>
<div class="container">
<form action="" method="get" >
<label>Node Path:</label>
<input id="text" type="text" name ="path" />
<input type= "submit" value="submit" />
</form>
</div>
<div>
<br>
<br>
<%! String absolutePath; %>
<%
com.intel.package1.HelloService service = sling.getService( com.intel.package1.HelloService.class);
String path = request.getParameter("path") ;
if (path != null){
java.util.List nodeNames = service.getNodeNames(path);
java.util.List nodePaths= service.getNodePaths(path);
java.util.List nodeDepths = service.getNodeDepths(path);
for (int i=0;i<nodeNames.size();i++){
int depth = (int)nodeDepths.get(i);
for(int j=0;j<depth;j++){
out.println("     ");
}
absolutePath= "http://localhost:4502/crx/de/index.jsp#"+nodePaths.get(i);
String start = "<a href='' onclick='fns()'>";
out.println(start+nodeNames.get(i)+"</a>" );
out.println("<br>");
// for(int j=0;j<depth;j++){
// out.println("     ");
// }
// out.println(absolutePath);
out.println("<br>");
// out.println("<br>");
}
}
%>
</div>
<script>
function fns (){
var value= "<%=absolutePath%>";
//alert('hello');
window.open(value, '_blank');
}
</script>
</body>
</html>
如何使 HTML 中的“href”属性动态化?
好吧,你有一个你想要的值的变量......
absolutePath= "http://localhost:4502/crx/de/index.jsp#"+nodePaths.get(i); String start = "<a href='' onclick='fns()'>";
......所以只需使用它:
String start = "<a href='" + absolutePath +"'>";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句