1. JSP文件:
路径: D:/liferay/ext/ext-web/docroot/html/portlet/ext/myjspportlet
view.jsp
<%@ include file="/html/portlet/ext/myjspportlet/init.jsp" %>
<a href="<portlet:renderURL windowState="<%= WindowState.MAXIMIZED.toString() %>" />">Hello Everyone!</a>
init.jsp
<%@ include file="/html/common/init.jsp" %>
<portlet:defineObjects />
<%
PortletPreferences preferences = renderRequest.getPreferences();
%>
2. portlet 配置:
路径:D:/liferay/ext/ext-web/docroot/WEB-INF
portlet-ext.xml
<portlet-app>
......
<portlet>
<portlet-name>EXT_2</portlet-name>
<display-name>My JSPPortlet</display-name>
<portlet-class>com.ext.portlet.JSPPortlet</portlet-class>
<init-param>
<name>view-jsp</name>
<value>/ext/myjspportlet/view.jsp</value>
</init-param>
<expiration-cache>300</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>My JSP Portlet</title>
</portlet-info>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>
路径: D:/liferay/ext/ext-impl/classes/content
Language-ext.properties
......
javax.portlet.title.EXT_2=My JSP Portlet
3. java 源码
com.ext.portlet.JSPPortlet.java
package com.ext.portlet;
import javax.portlet.GenericPortlet;
import javax.portlet.ActionRequest;
import javax.portlet.RenderRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import java.io.IOException;
import javax.portlet.PortletRequestDispatcher;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.ReleaseInfo;
import java.io.PrintWriter;
/**
* JSPPortlet Portlet Class
* @author Administrator
*/
public class JSPPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
//response.setContentType("text/html");
// 这里使用的是这个方法
//PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/JSPPortlet_view.jsp");
//dispatcher.include(request, response);
PrintWriter writer = response.getWriter();
writer.print("Hello Jean, nothing to worry about, keeping moving!");
writer.close();
}
public void doEdit(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/JSPPortlet_edit.jsp");
dispatcher.include(request, response);
}
public void doHelp(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/JSPPortlet_help.jsp");
dispatcher.include(request, response);
}
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {
}
}
4. deploy
以TEST/TEST 登录
增加APPLICATION: 添加:My JSP Porlet