JSR-168_Portlet指南(讲述具体实施168规范的实际,高级)

合集下载

安全全球桌面端口平台用户指南说明书

安全全球桌面端口平台用户指南说明书

Deploying and Configuring Secure Global Desktop PortletThis user guide provides a brief introduction about the Secure Global Desktop (SGD)portlet and explains how you can install and configure SGD portlet in Portal Server7.2.Secure Global Desktop Portlet The SGD portlet adheres to the JSR 168standard for writing portlets and aims to securely access and transfer information between SGD and Portal Server using SRA.The SGD portlet uses Single Sign-On mechanism and enables to launch Webtop sessions from within a portlet.The SGD portlet can be configured by setting the following preferences.▼To Deploy and Configure SGD Portlet Using portal Server Console ■Install Sun Java System Portal Server version 7.1or above.■Install SGD Server version 4.2.x or 4.3.x.■Deploy SGD portlet.■Login to Portal Server console and create a channel for SGD portlet.■Edit the portlet properties and set the preferences as mentioned below.Login to Portal Server console.Click Portals tab.The Portals page appears.In the Portals pane,click portal1.The Desktop Tasks and Attributes page appears.Select Enterprise Sample Org from the Select DN drop down list.UnderTasks,click Deploy Portlet.The Deploy Portlet wizard appears.In the Select Portal and DN page,select the Portal as portal 1and DN as Enterprise Sample [Org]and click Next.The Enter the Portlet WAR and Portlet Deployment Information page appears.Click Browse to choose the WAR file,Roles File,and Users file and click Next.The Verify Information page appears.Verify the information that you choose and click Next.The Results page appears.Click Finish to deploy the portlet.Click Manage Containers &Channels in the DesktopTasks and Attributes page.The Manage Containers and Channels for the Portal that you have selected (portal 1)appears.In the left pane,click WorkContainer from the list of available containers.The WorkContainer specific tasks and properties appear in the right pane.UnderTasks,click New Channel or Container.The New Channel or Container wizard appears.In the Specify Portal and DN for Channel or Container page,select Portal as portal 1,DN as Enterprise Sampe[Org],andType as Channel and click Next.The Specify Channel Type page appears.BeforeYou Begin12345678910111213Choose the ChannelType as Portlet Channel (JSR 168or JSR 286)and click Next.The Specify Provider/Portlet/Producer Name page appears.Select a Portlet from the list and click Next.The Specify Channel Name page appears.Specify a name for the channel that you create.For example,sgdportletchannel and click Next.The Review page appears.Review the information that you have provided for Channel type,Name,and Provider.Click Finish.The Results page appears.A message appears that a new channel has been created.Click Close.The new channel is created and listed under the WorkContainer in the left pane of the Manage Containersand Channels for portal 1page.The right pane displays the Tasks,Portlet Preferences,and Properties for thenew channel.Set the location property of the SGD portlet as URL for SGD for Web ually,this URL is an HTTP orHTTPS that refers the SGD Web Server.The default URL is http://localhost:80/axis/services/rpc/.For example,if you want to configure for ,using HTTPS on port 8080,theformat is https://:8080/axis/services/rpc/.Note –This URL is used by the web services client of the portlet.So,you can use the DNS name and port thatare appropriate for resolution and connection from the host running the portal application.Set the sgdaccess ,which is the access key to enable shared login between the portal application and SGDserver.Set the sgdaccess value provided in thetomcat-base /webapps/sgd/WEB-INF/classes/com/tarantella/tta/webservices/client/views/Resources.properties file on your SGD server.The sgdaccess value format looks somethingsimilar to this c2dkX3RydXN0ZWRfdXNlcjpJcSxnVDBHI2I0LVlxYUZAeFRkSA==.Note –The sgdaccess preference is optional.If you do not set this preference,set incorrectly,or if the thirdparty authentication is disabled in Secure Global Desktop server,you will be provided with the standard SGDlogin,form where you can choose to save the SGD credentials for automatic login later.Set theTarantella Client location,using the tcc-location preference.The base URL for the client can be set asoptional,using the tcc-location preference.You can use either an absolute or relative URL.When you use arelative URL,you can download the client from the portlet application.When you set the tcc-locationpreference to /tcc ,the portlet will proxy requests to the SGD Web Server.Note –This preference is for advanced ually,the Tarantella Client is downloaded directly from theSGD Web Server by the web browser.Set the tcc-sra-proxy-route preference (network connection rule),to enable the SGD client route its AIPtraffic through the SOCKS proxy using the local Netlet.This setting is only used,if the portlet detects that it isrunning through an SRA.If running in OpenPortal server mode,this setting is not used.For example,if the Netlet was listening on port 5555,the tcc-sra-proxy-route attribute will beCTSOCKS:localhost:5555or if SOCKS proxy is not used,then it is CTTTAP:localhost:5555.141516171819202122▼To Create and Configure a Static Netlet RuleFollow the steps to create and configure a static Netlet rule.Login to Portal Server console and navigate to Secure Remote Access ->Netlet.Select the appropriate DN,to specify the organization where you have deployed the SGD portlet and need toadd the Netlet rule.Create a new Netlet rule.To do this,navigate to Advanced ->Rules.Click create a new rule.Enter a Rule name.Type the Local port value as 5555.This is the port on which Netlet listens on the clientbrowser.Type the SOCK proxy server Fully Qualified Domain Name as Destination Host and SOCK proxy serverport as Destination Port.Save the Rule.12345Copyright2008Sun Microsystems,Inc.All rights reserved.Sun Microsystems,Inc.has intellectual property rights relating to technology embodied in the product that is described in this document.In particular,and without limitation,these intellectual property rights may include one or more U.S.patents or pending patent applications in the U.S.and in other countries.ernment Rights–Commercial ernment users are subject to the Sun Microsystems,Inc.standard license agreement and applicable provisions of the FAR and its supplements.This distribution may include materials developed by third parties.Parts of the product may be derived from Berkeley BSD systems,licensed from the University of California.UNIX is a registered trademark in the U.S.and other countries,exclusively licensed through X/Open Company,Ltd. Sun,Sun Microsystems,the Sun logo,the Solaris logo,the Java Coffee Cup logo,,Java,and Solaris are trademarks or registered trademarks of Sun Microsystems,Inc.in the U.S.and other countries.All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International,Inc.in the U.S.and other countries.Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems,Inc.The OPEN LOOK and Sun TM Graphical User Interface was developed by Sun Microsystems,Inc.for its users and licensees.Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry.Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface,which license also covers Sun's licensees who implement OPEN LOOK GUIs and otherwise comply with Sun's written license agreements.Products covered by and information contained in this publication are controlled by U.S.Export Control laws and may be subject to the export or import laws in other countries.Nuclear,missile,chemical or biological weapons or nuclear maritime end uses or end users,whether direct or indirect,are strictly prohibited.Export or reexport to countries subject to U.S.embargo or to entities identified on U.S.export exclusion lists,including,but not limited to,the denied persons and specially designated nationals lists is strictly prohibited.DOCUMENTATION IS PROVIDED“AS IS”AND ALL EXPRESS OR IMPLIED CONDITIONS,REPRESENTATIONS AND WARRANTIES,INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT,ARE DISCLAIMED,EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.820-4274Sun Microsystems,Inc.4150Network Circle,Santa Clara,CA95054U.S.A.。

JSR168规范详解

JSR168规范详解

JSR168规范详解关于Portlet的一些概念性的文字网络上很多,谷歌或是百度一下可以很容易搜索到,下面我把自己觉得容易混淆和模糊的几个知识点做下简单介绍:1、Portlet Request & URL在一个Portal 页面中,通常都包含了多个Portlet ,在一个时刻用户只能与一个Portlet 交互,当用户向一个Portlet 发出请求(例如点击了“ submit ”按钮),整个Portlet 页面将会重新构成。

在这个过程中,是否有与用户交互的Portlet 处理方式显然是不同的,而且用户没有与之交互的Portlet 显然不应该接收到用户的请求参数。

因此JSR168 规范中将对Portlet 的请求分为Action 和Render 两种。

Portlet 在收到Action 请求,获取用户所提交的信息,进行相应的处理;受到Render 请求后,则生成页面代码。

当用户向一个Portlet 发出请求,该请求被Portlet 容器接受,Portlet 容器再调用相应Portlet 的processAction() 方法;等到processAction() 方法执行完毕后,Portlet 容器再调用所有Portlet 的render() 方法,并将这些方法所返回的内容组合形成一个页面返回给客户端。

在上述过程中,所有Portlet 的render() 方法的调用次序在规范中没有规定,既可能是有顺序的串行调用,也可能是多线程的同步调用,依赖于厂商的具体实现。

为了接受用户请求,一个Portlet 需要有一个指向其自身的URL ,例如用在HTTP FORM 的ACTION 字段。

但是与Servlet 不同的是,Portlet 不是一个完整的页面而只是页面的一部分,一个Portlet 可以出现在多个页面中,所以Portlet 无法绑定具体的URL 。

在JSR168 规范中定义了PortletURL 接口,通过该接口可以得到指向Portlet 自身的URL ,对应两种用户请求有两种产生URL 的方法:q?4k2@*v_rk*l一、for render():PortletURL url = response.createRenderURL(); &S A(`L v(surl.setParameter(“customer”,””);url.setParameter(“show”,”summary”);writer.print(“<A HREF=\””+url.toString()+”\”>Summary</A>”);二、for processAction():`kTi3OPortletURL url = response.createActionURL();url.setParameter(“paymentMethod”,”creditCardInProfile”);url.setWindowState(WindowState.MAXIMIZED); 1x"p VfHwriter.print(“<FORM METHOD=\”POST\” ACTION=\””+ url.toString()+”\”>”);(r/aI iI(v/i上面的代码我们可以看到,除了得到URL 外,还可以在其中加入参数。

Java开源门户系统

Java开源门户系统

Liferay代表了完整的J2EE应用,使用了Web、EJB以及JMS等技术,特别是其前台界面部分使用Struts 框架技术,基于XML的portlet配置文件可以自由地动态扩展,使用了Web Services来支持一些远程信息的获取,使用Apahce Lucene实现全文检索功能。

主要特点:1、提供单一登陆接口,多认证模式(LDAP或SQL);2、管理员能通过用户界面轻松管理用户,组,角色;3、用户能可以根据需要定制个性化的portal layout;4、能够在主流的J2EE应用服务器上运行,如JBoss+Jetty/Tomcat,JOnAS;5、支持主流的数据库,如PostgreSQL,MySQL;6、使用了第三放的开源项目,如Hibernate, Lucene, Struts;7、支持包括中文在内的多种语言;8、采用最先进的技术Java, EJB, JMS, SOAP, XML;JetSpeedJetspeed是一个开放源代码的企业信息门户(EIP)的实现, 使用的技术是Java和XML. 用户可以使用浏览器, 支持WAP协议的手机或者其它的设备访问Jetspeed架设的信息门户获取信息. Jetspeed扮演着信息集中器的角色, 它能够把信息集中起来并且很容易地提供给用户.Jetspeed具有如下的特征:* 即将成为标准化的Java Portlet API* 基于模板的布局, 包括JSP和Velocity* 通过开放的内容同步技术支持远程XML内容交换* 定制默认的主页* 使用数据库进行用户认证* 内存缓存技术, 加快页面的响应* 通过Rich Site Summary技术, 支持同步内容* 和Cocoon, WebMacro, Velocity集成.* Wireless Markup Language (WML) 支持* 使用XML格式的配置文件注册portlet.* 完整的Web Application Archive (WAR) 支持* Web应用程序开发的基础设施* 可以在本地缓存远程内容* 与Avantgo同步* 可移植到所有支持JDK1.2和Servlet 2.2的平台* 与Turbine模块和服务集成* 可以根据用户, 安装媒体类型和语言的不同设定, 产生不同的个性化服务* 持续化服务使得所由的portlet能够容易的存储每个用户的状态, 页面和portlet* 使用皮肤技术使得用户可以选择portlet的颜色和显示属性* 自定义功能是的管理员可以选择portlet以及定义个人页面的布局* 在数据库中存储PSML* 通过Jetspeed的安全portlets管理用户, 组,角色和权限* 基于角色对访问portlet进行控制PlutoPluto是一个满足Portlet API规范的Portlet容器的实现,它为开发者提供了一个运行portlets的工作平台。

什么是portal

什么是portal

关于portal的技术资料摘录:什么是Portal?Portal是一个基于web的应用程序,它主要提供个性化、单点登录、不同来源的内容整合以及存放信息系统的表示层。

什么是Portlet?Portlet是基于java技术的web组件,它由portlet容器管理、并处理请求,并动态生成输出内容。

Portlet是基于java的web组件,由portlet容器管理,并由容器处理请求,生产动态内容。

Portals 使用portlets作为可插拔用户接口组件,提供信息系统的表示层。

作为利用servlets进行web 应用编程的下一步,portlets实现了web应用的模块化和用户中心化。

portlet规范,即jsr(java specification request)168,是为了实现portal和portlet的互操作。

它定义了portlet和portlet 容器之间的和约,让portlet实现个性化、表示和安全的api集。

规范还定义了怎样在portlets应用中打包portlets。

Portal标准为规范Portal,SUN于2003年底制定了JSR168,它定义了portlet标准,并给出了一个实现接口。

Portlets与Servlet的异同?相同点基于web应用的java技术由特定的容器管理动态生成内容生命周期由容器进行管理通过request/reponse进行交互不同点portlet只生成片段portlet并不直接绑定到某一个URL上portlet通过portal进行交互portlet可以多次在同一个portal页面上同时出现portlet优点能访问到用户配置信息能在不同的域中存储会话:应用程序级到私有级。

portlet与servlet的关系前者能调用后者,并且能共享信息,包括:Attributesportlet容器是servlet容器的扩展portlet无法做到的事情设置response的字符集编码设置http header获取客户端的requestPortlets实例如果是在普通的场合下使用,即不是在分布式场合,则每个portal应用就会生成一个portlet实例。

Portal产品分析报告(1)

Portal产品分析报告(1)

PORTAL产品分析报告(1)徐亚斌Portal是web应用进展的一个重要趋势,目前几乎所有大的软件厂商都有自己的Portal 产品。

同时Portal技术已经形成规范。

本文对Portal技术与产品进行了分析,目的是为公司产品的规划提供参考。

本文包含4个部分:Portal简介、Portal厂商及Portlet规范、Portal 技术分析、有关技术-JSF。

Portal简介介绍了Potal的概念,Portal的进展等基本情况。

Portal技术分析介绍了Portal技术的核心概念与实现思路。

由于组件化web页面开发对Portal技术及公司产品都有很大的影响,因此在本文的第四个部分专门介绍了组件化web页面开发的技术JSF。

1Portal简介1.1 Portal的概念从上面的定义能够看出,Portal的核心思想是网页个性化,它有两个含义,一是为不一致的网页访问者匹配不一致的内容(信息),二是为不一致的网页访问者提供不一致的portlet 应用服务,并在所能提供服务的基础上根据访问者的不一致相应改变处理流程。

这个理念与CRM的理念非常相似。

下面从Portal的分类开始,介绍Portal的进展过程。

1.2 Portal的分类随着web应用的进展,又出现了Vertical Portal与Enterprise Information Portal。

Vertical Portal即行业门户,目的是帮助某一行业的商业人员与技术人员找到自已需要的特定行业的商业信息与技术信息。

Enterprise Information Portal(EIP)即企业信息门户。

目的是帮助企业用户及员工通过统一入口找到分布于企业的各类信息。

与Public Porta相似,lVertical Portal 与EIP也同样提供了检索、分类与个性化定制服务。

在以上三种Portal中,EIP出现的包含内容最多。

因此下文中的Portal,假如不特别声名,指的就是EIP。

portal技术

portal技术

基于Struts2构建WebSphere Portal上的Portlet应用收藏Struts 2 是MVC 框架发展的最新阶段。

Struts 2 从WebWork 发展而来,而不是由Struts 1 演化而来,因此利用Struts 2 开发和部署应用程序有很多不同于Struts 1 的地方,尤其是在开发和部署Porlet 方面,Struts 2 更是有着以往Portlet 应用程序开发方式所无法比拟的优势。

本文的目的就是通过在IBM 的WebSphere Portal Server 上开发和部署一个基于Struts 2 的Porlet 应用,向读者介绍利用Struts 2 进行Portlet 应用开发的优势和关键流程。

概述WebSphere Portal Server5.1 及以上版本支持两种Portlet API:第一种是IBM Portlet,这种Portlet API 是WebSphere Portal Server 专有的一种Portlet API;第二种是符合JSR168 标准的Portlet API。

由于JSR168 是一个开放的标准,因此符合JSR168 标准的Portlet 将更易于移植。

IBM 为IBM Portlet API 和JSR168API 分别实现了基于Struts1 的Portlet 开发框架,由于基于Struts1,这两种Portlet 框架API 同Portlet API 耦合紧密,尤其需要指出的是由于无论IBM Portlet 还是在WebSphere Portal Server 上实现的JSR168 标准的Porlet API, 它们的接口都直接依赖于PortletRequest/PortletResponse 对象,这就使得程序移植和单元测试等变得比较困难。

此外,我们在使用Struts1 开发Servlet 应用时,习惯于将数据存放在request 作用域中,通过页面的跳转将数据呈现到jsp 视图页面。

Liferay Portal 6学习笔记

單點登錄:Portal通常采用ACL、SSL、LDAP等業界標准的安全技術,提供對所有現有應用系統的安全集成,只需在Portal的唯一入口上登錄一次,就可以訪問所有應用系統和數據。對於安全性要求較高的應用系統,如電子商務平台、交易系統等,通過擴展接口傳遞用戶身份信息,如數字證書信息、數字簽名信息等,進行二次身份認證,保證單點登陆的安全性。
Portlet
Portlet被定義成为一個新的組件,具有新的明確的界面與行为。为了盡可能與現有的Servlet結合達到重复使用的目的,Portlet的規範利用了Servlet的規範,許多觀念都很相似的,結合Portlet、Servlet及Jsp在同一個網站系統中,我們稱为Portlet應用。在同一個Portlet應用中,他們將分享同一個類加載器(ClassLoader),上下文(Context)及Session。
權限控制:系統采用LDAP對用戶資源進行統一的管理,同時提供二次開發接口,可以與其他應用系統的用戶管理模塊對接,並能隨相關業務系統實時更新訪問權限。通過完善的授權機制及存取控制,用戶訪問權限控制到字段級別,確保用戶只能訪問具有權限的應用系統及相關信息。
內容管理:實現應用系統之間實時交換信息。采用多種緩存機制,保證內容交換的性能和准確性。采用基於XML的Rich Site Summary (RSS)標准,迅速在各應用系統之間傳播最新變化。
什麼是
Portlet是Portal中最重要的組件,負責在Portal中呈現信息內容,有相應的生命周期。通過自定義Portlet,用戶很容易定義個性化的Portal頁面。Portlet由Portlet容器負責管理、處理請求並返回動態頁面,可以作为Portal的可即插即用的界面組件。
Portlet
一個Portlet是以Java技術为技術的Web組件,由Portlet容器所管理,專門處理客戶的信息請求以及產生各種動態的信息內容。Portlet为可插式的客戶界面組件,提供呈現層成为一個信息系統。

Portal开发的一些常用方法和函数介绍

把基于jsr168的Portlet开发的一些小技巧和小知识记录下来,作为一种备忘和知识积累,便于以后察看。

1. javabean的写法- java页面的代码:public void doView(RenderRequest request, RenderResponse response)throws PortletException, IOException {request.setAttribute("username","liuzhaoy ##################");}- jsp页面的写法<jsp:useBean id="username" class="ng.String"scope="request"></jsp:useBean><%=username %>- 展示结果2. 页面编码的写法<%@ page import="javax.portlet.*, java.util.*" session="false"%><%@ taglib uri="/portlet" prefix="portletAPI" %><%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" %>如果让其支持汉语,就改为:gb2312喽,呵呵。

3. 图片路径的写法<IMG src="<%=renderRequest.getContextPath()%>/testportlet/images/mark.gif"><br> <IMGsrc="<%=renderResponse.encodeURL(renderRequest.getContextPath()+"/testportlet/i mages/mark.gif")%>">其中renderResponse.encodeURL表示编码。

X5业务架构平台产品白皮书

X5业务架构平台产品白皮书Justep X5业务架构平台产品白皮书起步科技目录1X5业务架构平台简介 (1)1.1X5业务架构平台简介 (1)1.2X5业务架构平台的主要用途 (2)1.3X5业务架构平台基本思想 (2)1.4X5业务架构平台实现原理、方法和产品集 (4)1.5产品结构 (7)2X5业务架构平台关键能力 (10)2.1灵活调整和自由扩展 (11)基于“白盒”模式的灵活调整 (11)管理软件“白盒”化的基础 (13)基于“主板+插件”模式的自由扩展 (14)客户化定制和维护能力 (18)2.2组织机构和权限管理 (19)团队和组织机构管理 (20)业务分工和权限管理 (22)组织架构和权限管理的特点 (24)2.3业务工作流 (27)与业务模型高度融合的工作流体系 (27)强大的工作流模式和能力支持 (29)强大的协作支持能力 (34)运行监控和分析能力 (38)扩展和控制能力 (42)2.4表单和报表 (45)强大的文档支持能力 (45)强大的表格和报表支持 (52)强大的网格支持 (58)丰富的图表支持 (59)2.5业务集成和业务门户 (60)X5集成能力 (60)X5业务集成 (66)X5业务门户 (69)2.6查询、统计和决策分析 (71)查询统计能力 (71)决策分析能力 (74)过程分析能力 (77)2.7快速实施和部署 (79)高效的实施模式 (80)快速实施部署能力 (86)2.8业务支撑架构 (93)业务支撑架构的组成 (93)业务支撑架构的主要作用 (94)X5业务架构平台关键特征 (95)2.9快速构建和业务建模 (97)X5快速构建能力 (97)X5业务架构平台业务建模 (99)X5 Studio业务建模工具 (104)3JUSTEP X5技术体系与特性 (108)3.1J USTEP X5业务架构平台关键技术特性 (108)3.2技术体系综述 (109)3.3基础技术体系 (110)3.4业务模型体系 (111)业务概念模型 (112)用户界面模型 (117)业务流程模型 (122)组织权限模型 (125)1 X5业务架构平台简介1.1X5业务架构平台简介Justep X5业务架构平台是从信息化的整体、全局和发展的角度出发,为保障信息化成功而提供的战略支撑工具。

Vaadin入门


• • • • • • • • • • • • • • • • • • • • •
import com.Vaadin.Application; import com.Vaadin.ui.*; import com.Vaadin.ui.Button.ClickEvent; public class Dw_Vaadin_projectApplication extends Application { Window window; public void init() { Window main = new Window("Dw_Vaadin_project Application"); setMainWindow(main); window=new Window("Sub Window"); main.addWindow(window); window.setVisible(false); Button button=new Button("Show window once"); /*... 在 Button 上注册左键点击监听器 ...*/ button.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { window.setVisible(true); } }); main.addComponent(button); } }
Vaadin UI 组件的事件监听和处理 机制
• Vaadin 使用 Observer 设计模式来处理用户界面 操作和程序逡辑之间的通讯。这一模式使用两类元 素:一个被观测的对象 (object) 和若干个监听不被 观测对象相关的事件的观察者 (observer), 当一个 不被观测对象相关的事件发生时,观测者会接受到 该事件的消息通知,并且根据程序的业务逡辑执行 后续操作。在 Vaadin 中 , 观测者被称作监听器 (listeners),而被观测者通常为程序中的 UI 组件。 • 在 Vaadin 中,Listener 由 AbstractComponent 类管理 , 这个类是所有 UI 组件的父类,
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

摘要JSR-168是适合于portlet开发人员的Java API集合。

设计符合规范的JSR-168 portlet的原因有很多。

可移植性就一个显而易见的好处。

根据规范编写的代码更容易在门户服务器之间移动。

多数基于Java的门户服务器都支持JSR-168 portlet。

另一个好处是更易于联合。

当portlet符合JSR-168规范时,通过Web Services for Remote Portlets (WSRP)生产者公开JSR-168 Portlet会更容易一些。

WSRP提供了一个通过Web service 联合portlet内容的标准。

JSR-168和WSRP 1.0 portlet功能是紧密耦合的。

JSR-168 to WSRP portlet桥利用JSR-168的URL重写API。

本文将阐述开发JSR-168 portlet以便获得可移植性的最佳实践。

1. 总是利用URL重写API,以获得Portlet中的内容Java开发人员经常在如下所示JSP中编写图像的URL:<img src="/<%= request.getContextPath()%>/images/logo.gif"/> 这在JSR-168 portlet中是不正确的。

正确的方法是:<img src="<%= renderResponse.encodeURL(renderRequest.getContextPath()+"/images/logo.gif") %>"/>encodeURL()方法可以采用完全路径URI或者完全限定URL。

完全路径URI是最常用的。

在使用JSR-168 portlet将资源嵌入Web Application Archive (WAR)中时,可以使用此技术。

在将图像放置到单独服务器上时,可以使用完全限定URL。

专门为静态内容提供服务的缓存服务器就是一个示例,它卸掉来自门户服务器的通信量。

尽管可以通过对完全限定URL使用encodeURL()来引用portlet以外的内容,但应该只在无法通过客户机访问资源时这样做。

如果客户机可以直接浏览资源,则无需对URL使用encodeURL()。

例如,如果有一台Web服务器,可用该服务器获得门户用户无法直接浏览的防火墙内的静态内容,则需要调用encodeURL()。

如果这些内容在防火墙之外,并且门户用户可以直接浏览到Web服务器,则无需调用encodeURL()。

2. 不要将路径附加到重写URL中传入RenderRequest的encodeUrl()方法中的URL在调用该方法之前必须是完整的。

在调用该方法之后,无法添加URL的某些部分。

例如,如果想从XSLT转换中生成一个URL转换,则不能将已编码的基本URL(/)作为参数传递,并将路径(pages/bar.jsp)附加到该转换中的已编码基本URL中。

以下调用演示了将URL编码到图像中的正确方式:<@= renderResponse.encodeURL(renderRequest.getContextPath()+"/images/logo.gif")@>它使用一个.portal文件在BEA WebLogic Portal 9.2中生成以下HTML片段:<img src="http://localhost:7001/PortalWebApp/images/logo.gif;PORTAL_TAU=W3f6FbmLLcgZq9Fpv1JHLs5rrJG8Lgj2nnDVJqdfShhRGFnsqCKZ!-545815275" />以下调用是不正确的。

URL并不指向想要的资源。

<@= renderResponse.encodeURL(renderRequest.getContextPath()+ "/images/")+"logo.gif"@>它使用.portal文件在WebLogic Portal 9.2中生成以下HTML文件:<img src="http://localhost:7001/PortalWebApp/images/;PORTAL_TAU=W3f6FbmLLcgZq9Fpv1JHLs5rrJG8Lgj2nnDVJqdfShhRGFnsqCKZ!-545815275l ogo.gif"/>3. 使用名称空间限定客户端脚本变量和方法假设您想使用portlet中的JavaScript验证用户输入。

以下JavaScript功能可能很有用:<script>function validate(foo) {if (foo.bar.value=="") {return false;}return true;}</script>同一页面中的其他portlet可能也有一个命名为validate()的具有不同逻辑的JavaScript方法。

门户框架本身可能使用JavaScript方法。

这个问题的解决方法是使用客户端脚本中的名称空间方法和顶层变量。

<portlet:namespace/>标记将为每个portlet生成一个惟一标识符。

第一步是通过taglib directive将标记库包含在JSP中。

<%@taglib uri="/portlet" prefix="portlet"%> 脚本中的validate()方法可以对标记加以区分。

<script>function validate<portlet:namespace/>(foo) {if (foo.bar.value=="") {return false;}return true;}</script>以下是调用带名称空间的JavaScript方法的方式:<form action="/servlet"method="GET" onsubmit="return validate<portlet:namespace/>(this);"><label for="bar">Text(required): </label><input type="text" name="bar" id="bar"></form>4. 确保引用Portlet资源的内联客户端脚本符合规范客户端脚本常常引用外部资源(如图像、电影和外部页面)来增强用户界面。

常见的示例是预先加载图像以使交换图像更有效的JavaScript。

以下是一个示例:<script>function preloadImages(){var menuImage =new Image();menuImage.src = "images/icon.gif";var menuImageDark=new Image();menuImageDark.src = "images/icon.gif";}</script>客户端脚本中的URL必须根据JSR-168规范进行重写。

这些脚本必须在JSP或JSP-168 portlet类中,以便调用重写API的URL。

它们不能在单独的JavaScript (.js)文件中。

以下是一个包含URL重写的适当名称空间脚本在JSR-168 portlet中看起来的样子:<script>function <portlet:namespace/>preloadImages(){var menuImage = new Image();menuImage.src ="<%=renderResponse.encodeURL(renderRequest.getContextPath()+"images/icon.gif")%>";var menuImageDark= new Image();menuImageDark.src ="<%=renderResponse.encodeURL(renderRequest.getContextPath()+"images/icon_dark.gif") %>";}</script>5. 总是为portlet响应声明一个内容类型根据JSR-168规范,“portlet必须使用RenderResponse接口的setContentType方法设置响应的内容类型”。

没有显式设置其内容类型的portlet仍然会成功获得编译。

但WebLogic Portal不会执行没有设置其内容类型的portlet。

确保您的portlet设置了其内容类型。

以下示例演示了一个正确设置其内容类型的portlet:public class MyPortlet extends GenericPortlet {public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {response.setContentType("text/html");PrintWriter writer = response.getWriter();writer.println("I set my content type!");}}此示例是不正确的,但仍将获得编译:public class MyPortlet extends GenericPortlet {public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {// no content type set!PrintWriter writer = response.getWriter();writer.println("I did NOT set my content type!");}}6. 不要从Portlet发送Cookie根据JSR-168 portlet规范,在HttpServletResponse上调用addCookie()实际上不会设置一个cookie。

相关文档
最新文档