从Liferay Portal调用jsp页面

时间:2016-07-11 17:17:22

标签: jsp liferay liferay-6

我是Liferay开发中的新手,我有一个非常简单的问题。

我有一个显示文本消息的portlet示例,我需要在Liferay Portal中显示。我怎样才能做到这一点 ? JSP代码如下:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
<%@ page import="javax.portlet.PortletPreferences" %> 

<portlet:defineObjects /> 

<% 
     PortletPreferences prefs = renderRequest.getPreferences();
     String greeting = (String)prefs.getValue( "greeting", "Hello! Welcome to our portal."); 
%>

<p><%= greeting %></p>

1 个答案:

答案 0 :(得分:1)

EDIT

How can I write the same portlet without java code in view.jsp file?

You must override MVCPortlets doView method to initialize an attribute, let's consider the attribute greeting. For example:

public class Greeting extends MVCPortlet {

    @Override
    public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {

        renderRequest.setAttribute("greeting", "Hello! Welcome to our portal.");

        super.doView(renderRequest, renderResponse);
    }
}

And in your JSP file, retrieve the greeting attribute using EL ${greeting}.

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 

<portlet:defineObjects /> 

<p>${greeting}</p>

Ouput:

Hello! Welcome to our portal.