Liferay Portal简单的demo

在myeclipse里创建一个简单的Web Project:

 

(1)在src下创建一个类,继承GenericPortlet,代码如下:

package com.portlet; import java.io.IOException; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.GenericPortlet; import javax.portlet.PortletException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; public class MytablePortlet extends GenericPortlet { @Override protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { String name = request.getParameter("name"); if(name == null || "".equals(name)){ this.getPortletContext().getRequestDispatcher("/table.jsp").include(request, response); } else{ this.getPortletContext().getRequestDispatcher("/display.jsp?username="+name).include(request, response); } } @Override protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { this.getPortletContext().getRequestDispatcher("/table.jsp").include(request, response); } @Override public void processAction(ActionRequest arg0, ActionResponse arg1) throws PortletException, IOException { System.out.println("processAction method"); } @Override public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException { this.doView(request, response); } }

 

 

(2)创建table.jsp,display.jsp代码分别为:

     1.table.jsp:

      <%@page import="javax.portlet.PortletURL"%> <%@page import="javax.portlet.RenderResponse"%> <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%> <%@ page language="java" contentType="text/html;charset=gbk" %> <% //这里提示会报错,找不到对象,但是不用管(是这个样子的) PortletURL pu = renderResponse.createRenderURL(); pu.setParameter("aaa","bbb"); //PortletURL pu = ((RenderResponse)response).createActionURL(); %>

username:

 

    2.display.jsp:

     <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%> <%@ page language="java" contentType="text/html;charset=gbk" %> <% String name = request.getParameter("username"); %>

欢迎光临,<%=name %>

 

(3)下载 liferay-portal-tomcat-4.2.1.zip解压到 F:/liferay/tomcat 目录下(我的机子上时这么做的)

 

(4)到 F:/liferay/tomcat/webapps/ROOT/WEB-INF 目录下配置三个xml文件

     1.在 portlet-ext.xml 文件中加入:

     MytablePortlet MytablePortlet com.portlet.MytablePortlet 0 text/html text/html edit MytablePortlet MytablePortlet MytablePortlet portlet-title show-portlet-borders true guest power user user

 

    2.在 liferay-portlet-ext.xml 文件中加入:

    

     MytablePortlet true true

 

    3. 在 liferay-display.xml 文件中加入:

    

 

 

(5)把.class文件copy到对应的 F:/liferay/tomcat/webapps/ROOT/WEB-INF/classes目录下

 

 

(6)启动 F:/liferay/tomcat/bin 下的startup.bat服务,程序就可以跑起来了

你可能感兴趣的:(Liferay,Portal)