一、文件目录结构如下:
├─libs
│ portlet-api_2.0_spec-1.0.jar
├─src
│ └─hello
│ HelloPortlet.java
└─WebContent
└─WEB-INF
│ portlet.xml
│ web.xml
├─classes
│ └─hello
│ HelloPortlet.class
1.HelloPortlet.java
package hello;
import java.io.IOException;
import java.io.PrintWriter;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletURL;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
public class HelloPortlet extends GenericPortlet {
protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
PrintWriter writer = new PrintWriter(response.getWriter());
writer.println("You're now in Edit mode.");
}
protected void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
PrintWriter writer = new PrintWriter(response.getWriter());
writer.println("You're now in Help mode.");
}
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
response.setContentType("text/html");
PrintWriter writer = new PrintWriter(response.getWriter());
writer.println("You're in View mode.<br>");
}
}
2.portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>HelloPortlet</portlet-name>
<display-name>Hello Portlet</display-name>
<portlet-class>hello.HelloPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
<portlet-mode>EDIT</portlet-mode>
<portlet-mode>HELP</portlet-mode>
</supports>
<portlet-info>
<title>Hello, This is my first portlet application</title>
</portlet-info>
</portlet>
</portlet-app>
3.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>pa2</display-name>
<servlet>
<servlet-name>HelloPortlet</servlet-name>
<servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-name</param-name>
<param-value>HelloPortlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloPortlet</servlet-name>
<url-pattern>/PlutoInvoker/HelloPortlet</url-pattern>
</servlet-mapping>
</web-app>
二、修改文件pluto-2.0.3\webapps\pluto\WEB-INF\pluto-portal-driver-config.xml,添加如下内容
<page name="HelloWorld" uri="/WEB-INF/themes/pluto-default-theme.jsp">
<portlet context="/pa2" name="HelloPortlet"/>
</page>
三、启动pluto-2.0.3