문제

I'm a writing an application using Spring MVC which has to run as a servlet and a portlet. This is fair easy to do in Spring 3 (JSR-286) but I must use portlet 1.0 specification (JSR-168). In order to be compatible with it I downgraded Spring MVC to 2.5 (more information here).

Everything works fine expect I'm not able to generate servlet/portlet compatible URL!

Using Spring 3, I would write:

<spring:url value="/foo">
  <spring:param name="action" value="foo"/>
</spring>

In Spring 2.5 there is no spring:url tag. I tried with c:url but it only generates servlet compatible URL (not portlet).

How can I achieve servlet/portlet compatible URL generation?

도움이 되었습니까?

해결책

I am not sure about the solution below, but maybe it will help.

You could use the portlet tag for portlet compatible urls :

<%@ taglib uri=”http://java.sun.com/portlet” prefix=”portlet” %>
...
<portlet:actionURL ... >
    <portlet:param name="action" value="foo">
</portlet:actionURL> 

(I recommend that you to take a look at the Java Portlet 1.0 specification (JSR-168) "Portlet Tag Library" chapter for detailed information about this tag)

Then, to generate either a portlet or a servlet url, you could use a condition that detects if you are currently using Portlet or Servlet (I don't know if it is possible) :

<c:choose>
    <c:when test="usingPortlet">
        <portlet:actionURL ... > ... </portlet:actionURL>
    </c:when>
    <c:otherwise>
        <c:url ... > ... </c:url>
    </c:otherwise> 
<c:choose>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top