开发者

Using jsp:param / c:param in a Portlet Environment

开发者 https://www.devze.com 2022-12-21 17:34 出处:网络
I\'m trying to include JSP pages wit开发者_运维百科h jsp:param in a Portlet environment (using the Pluto portlet container).

I'm trying to include JSP pages wit开发者_运维百科h jsp:param in a Portlet environment (using the Pluto portlet container).

for example,

<jsp:include page="test.jsp">
   <jsp:param name="foo" value="bar"/>
</jsp:include>

and in test.jsp,

<c:out value="${foo}"/> or <%= request.getParameter("foo") %>

The output is always null and i've also tried using c tags, but got the same result.

<c:import url="test.jsp">
   <c:param name="foo" value="bar"/>
</c:import>

I've searched through the net and many people have faced the same problem, except that there is no solution to it.

Is this a limitation or is there a different way to do it?


This works fine in a normal Servlet environment, but I see from a bit of googling that the portlet environment seems to break it. This is a shame, but indicative that the portlet spec is, to put it bluntly, broken.

If <jsp:param> won't work for you, the alternative is to use request attributes instead:

<c:set var="foo" value="bar" scope="request"/>
<jsp:include page="test.jsp"/>

And in test.jsp:

<c:out value="${requestScope.foo}"/>

or maybe just:

<c:out value="${foo}"/>

It's not as neat and contained as using params, but it should work for portlets.


I had the same problem. My solution was to work with Portlet's renderRequest object (which is accessible from included jsp files). In my portlet I set the attribute on the RenderRequest object then in my JSP (included via jsp:include). I use Portlet API to access the implicit renderRequest object. Here is a sample:

MyPortlet:

public void doView(RenderRequest request, RenderResponse response) {
  request.setAttribute("myBean", new MyBean());
  getPortletContext().getRequestDispatcher("myMainJSP.jsp").include(request, response);
}

myMainJSP.jsp:

<jsp:include page="header.jsp"/>

header.jsp:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<% page import="sample.MyBean" %>
<portlet:defineObjects/>
<%
  MyBean myBean = (MyBean)renderRequest.getAttribute("myBean");
%>
... html code...
0

精彩评论

暂无评论...
验证码 换一张
取 消