如何生成“返回搜索结果” url 通过 JSTL 或 JSP 中的自定义 lib 包含所有参数并指定排除参数?
我想在 JSP 中生成“返回搜索结果”URL。我使用 JSTL taglib 并且它有效:
<c:url var="backUrl" value="list.html">
<c:forEach items="${param}" var="currentParam">
<c:param name="${currentParam.key}" value="${currentParam.value}"/>
</c:forEach>
</c:url>
<a href="${backUrl}">< return to search results / list</a>
我想要一个更好的解决方案,例如自定义库来使用一行代码生成反向链接,例如:
<tagname:url var="backUrl" value="list.html" includeAllParams="true" excludeParams="id, question"/>
<a href="${backUrl}">< return to search results / list</a>
因为,我想通过排除参数重新使用此代码:
<c:url var="backUrl" value="list.html">
<c:forEach items="${param}" var="currentParam">
<c:if test="${currentParam.key ne 'id'}">
<c:param name="${currentParam.key}" value="${currentParam.value}"/>
</c:if>
</c:forEach>
</c:url>
<a href="${backUrl}">< return to search results / list</a>
我的问题最佳实践是什么以及如何创建自定义库来通过一行生成链接:
<tagname:url var="backUrl" value="list.html" includeAllParams="true" excludeParams="id, question"/>
谢谢。
I want to generate a 'back to search result' url in a JSP. I use JSTL taglib and it works:
<c:url var="backUrl" value="list.html">
<c:forEach items="${param}" var="currentParam">
<c:param name="${currentParam.key}" value="${currentParam.value}"/>
</c:forEach>
</c:url>
<a href="${backUrl}">< return to search results / list</a>
I want to have a better solution, like a custom lib to generate the back link with one line code, by example:
<tagname:url var="backUrl" value="list.html" includeAllParams="true" excludeParams="id, question"/>
<a href="${backUrl}">< return to search results / list</a>
Because, I want to re-use this code with an exclude param:
<c:url var="backUrl" value="list.html">
<c:forEach items="${param}" var="currentParam">
<c:if test="${currentParam.key ne 'id'}">
<c:param name="${currentParam.key}" value="${currentParam.value}"/>
</c:if>
</c:forEach>
</c:url>
<a href="${backUrl}">< return to search results / list</a>
My question is what is the best practice and how can I create a custom lib to generate link by one line:
<tagname:url var="backUrl" value="list.html" includeAllParams="true" excludeParams="id, question"/>
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我创建了一个自定义选项卡:
Class:
tld:
并在 jsp 中:
Ok, I have created a custom tab:
Class:
tld:
And in the jsp: