如何在Spring + JSP中创建超链接

编程入门 行业动态 更新时间:2024-10-10 08:19:00
本文介绍了如何在Spring + JSP中创建超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Spring + JSP中创建超链接的正确方法是什么?必须有一个比在< a href =...> 标记中编码更好的方法。以一个显示人物的页面为例。该URL为 people.htm 。相应的控制器从数据库中获取人员并执行可选的列排序。 JSP可能如下所示:

What's the proper way to create a hyperlink in Spring+JSP? There must be a better way than just coding in the <a href="..."> tag. Take for example a page that displays people. The URL is people.htm. The corresponding controller gets people from the database and performs optional column sorting. The JSP might look like:

<table> <tr> <td><a href="people.htm?sort=name">Name</a></td> <td><a href="people.htm?sort=age">Age</a></td> <td><a href="people.htm?sort=address">Address</a></td> </tr> ...

这似乎很糟糕,因为URL 人。 htm 在JSP中是硬编码的。应该有一种方法让Spring使用 servlet.xml 中定义的URL自动构建< a> 标记。

This seems bad as the URL people.htm is hardcoded in the JSP. There should be a way to have Spring automatically build the <a> tag using the URL defined in servlet.xml.

编辑:也许我应该使用Spring表单。

Edit: Maybe I should be using a Spring form.

推荐答案

唯一想到的是JSTL标准标签< c:url> 。 例如:

The only thing that comes to mind is the JSTL standard tag <c:url>. For example:

<c:url var="thisURL" value="homer.jsp"> <c:param name="iq" value="${homer.iq}"/> <c:param name="checkAgainst" value="marge simpson"/> </c:url> <a href="<c:out value="${thisURL}"/>">Next</a>

现在这不会让你获得servlet映射等,但什么都不会。这不是你可以用编程方式做的事情(毕竟,servlet可以并且通常映射到一系列URL)。但这将为你逃避。

Now this won't get you servlet mapping or the like but nothing will. It's not something you could really do programmatically (after all, a servlet can and usually does map to a range of URLs). But this will take care of escaping for you.

更多推荐

如何在Spring + JSP中创建超链接

本文发布于:2023-11-28 08:44:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:超链接   如何在   Spring   JSP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!