afunms

My Software,My Dream—Forge a more perfect NMS product.

portal demo

1、新建web工程testportal,向工程中添加portal2.0 jar包

2、创建portlet

package com.miiwill;

import java.io.IOException;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class Helloworld extends GenericPortlet {
    @Override
    
protected void doView(RenderRequest request, RenderResponse response) 
                   
throws PortletException, IOException {
        response.setContentType(
"text/html");
        response.getWriter().println(
"<h2>hello world,View Mode</h2>");
    }


    @Override  
    
protected void doEdit(RenderRequest request, RenderResponse response)   
        
throws PortletException, IOException {   
        response.setContentType(
"text/html");    
        response.getWriter().println(
"<h2>hello world,Edit Mode</h2>");   
    }
   
}


3、修改
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
    
<servlet>
        
<!--pluto通过servlet来知道哪个context是portlet,如果没有这个servlet,portlet就没法注册到pluto中-->
        
<servlet-name>HelloWorldPortal</servlet-name>
        
<!--在pluto1.0中是org.apache.pluto.core.PortletServlet-->        
        
<servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
        
<!--portlet的名字必须和portlet.xml中portlet的名字一致-->
        
<init-param>
            
<param-name>portlet-name</param-name>
            
<param-value>HelloWorldPortalDemo</param-value>
        
</init-param>
        
<!--唯一标识,每个portlet的标识应该都不同-->
        
<init-param>
            
<param-name>portlet-guid</param-name>
            
<param-value>HelloWorldPortal.HelloWorldPortalDemo</param-value>
        
</init-param>
        
<!--这个参数是告诉pluto,portlet名字所对应的类是什么-->
        
<init-param>
            
<param-name>portlet-class</param-name>
            
<param-value>com.miiwill.Helloworld</param-value>
        
</init-param>
        
<!--PortletServlet执行init时,根据charset参数获取字符集,
                               然后在执行响应时调用response.setContentType来设置编码
-->
        
<init-param>
            
<param-name>charset</param-name>
            
<param-value>utf-8</param-value>
        
</init-param>        
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<!--映射模板必须以/PlutoInvoker开头,否则pluto识别不出来-->
    
<servlet-mapping>
        
<servlet-name>HelloWorldPortal</servlet-name>
        
<url-pattern>/PlutoInvoker/*</url-pattern>
    
</servlet-mapping>
    
<welcome-file-list>
        
<welcome-file>index.jsp</welcome-file>
    
</welcome-file-list>
</web-app>


4、创建portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app
    
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
    version
="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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>
        
<description>My First Portal Demo</description>
        
<portlet-name>HelloWorldPortalDemo</portlet-name>
        
<display-name>HelloWorld Portal Demo</display-name>
        
<portlet-class>com.miiwill.Helloworld</portlet-class>
        
<expiration-cache>-1</expiration-cache>
        
<supports>
            
<mime-type>text/html</mime-type>
            
<portlet-mode>VIEW</portlet-mode>
            
<portlet-mode>EDIT</portlet-mode>
        
</supports>
        
<portlet-info>
            
<title>My First Portal Demo : HelloWorldPortal</title>
        
</portlet-info>
    
</portlet>
</portlet-app>


5、部署portal

将WebRoot copy到webapps下,改名为testportal。

注意将WEB-INF\lib中的2 个jar删除,因为pluto的lib中已经有了。不删除会有冲突!

 1)启动pluto,http://localhost:8080/pluto/

    以pluto/pluto登录。

 2)创建一个页


     3)注册portlet

     4)测试portlet

posted on 2011-09-30 09:07 afunms 阅读(610) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

My Links

News

留言簿(18)

随笔档案

相册

搜索

最新评论

阅读排行榜