我正在编写一个使用Spring MVC的应用程序,它必须作为 servlet 和 portlet 运行。这在Spring 3(JSR-286)中很容易实现,但我必须使用portlet 1.0规范(JSR-168)。为了与之兼容,我将Spring MVC降级为2.5(more information here)。
一切正常,期待我无法生成与servlet / portlet兼容的URL!
使用Spring 3,我会写:
<spring:url value="/foo">
<spring:param name="action" value="foo"/>
</spring>
在Spring 2.5中没有spring:url
标记。我尝试使用c:url
,但它只生成与servlet兼容的URL(而不是portlet)。
如何实现与servlet / portlet兼容的URL生成?
答案 0 :(得分:1)
我不确定下面的解决方案,但也许会有所帮助。
您可以将portlet标记用于portlet兼容的URL:
<%@ taglib uri=”http://java.sun.com/portlet” prefix=”portlet” %>
...
<portlet:actionURL ... >
<portlet:param name="action" value="foo">
</portlet:actionURL>
(我建议您查看Java Portlet 1.0 specification (JSR-168)“Portlet标记库”一章,了解有关此标记的详细信息)
然后,要生成portlet或servlet url,你可以使用一个条件来检测你当前是否正在使用Portlet或Servlet(我不知道是否可能):
<c:choose>
<c:when test="usingPortlet">
<portlet:actionURL ... > ... </portlet:actionURL>
</c:when>
<c:otherwise>
<c:url ... > ... </c:url>
</c:otherwise>
<c:choose>