How to obtain portal logon user information in themes and skins

Source: Internet
Author: User

1.1.1 Problem Description

Obtain logon user objects and retrieve user information such as user names and registered email addresses, which are frequently used in theme and skin development and Portlet development. How do I retrieve user information? We can achieve this by configuring the encoding method:

1.1.2 Solution

Method 1: Tag + code:

First modify

The default. jsp file under the IBM/WebSphere/wp_profile/installedapps/[cellname]/WPS. Ear/WPS. War/themes/html/themename directory:

1. Change <% @ page session = "false" buffer = "NONE" %> to <% @ page session = "true" %>

Import the jar package of IBM User. The package name is WP. User. API. jar,

You can find it in IBM/WebSphere/portalserver/base/WP. User. API/shared/app.

<% @ Page import = "com. IBM. wps. Puma. User" %>

Add the following code:

<%

Httpsession mysession = request. getsession ();

String loginname = "";

If (mysession. getattribute ("com. IBM. wps. util. session_user ")! = NULL ){

Com. IBM. wps. Puma. User myuser = (COM. IBM. wps. Puma. User) mysession. getattribute ("com. IBM. wps. util. session_user ");

Loginname = myuser. getfullname ();

}

%>

Method 2:

<% @ Page import = "com. IBM. Portal. Portlet. Service. portletservicehome" %>

<% @ Page import = "com. IBM. Portal. Portlet. Service. portletserviceunavailableexception" %>

<% @ Page import = "com. IBM. Portal. Puma. User" %>

<% @ Page import = "com. IBM. Portal. Um. pumahome" %>

<% @ Page import = "com. IBM. Portal. Um. pumaprofile" %>

<% @ Page import = "com. IBM. Portal. Um. Exceptions. pumaexception" %>

 

<%

Pumahome home = NULL;

Context CTX = new initialcontext ();

Portletservicehome servicehome = (portletservicehome) CTX. Lookup ("portletservice/COM. IBM. Portal. Um. portletservice. pumahome ");

Home = (pumahome) servicehome. getportletservice (pumahome. Class );

Pumahome = home;

Pumaprofile = pumahome. getprofile ();

String currentusername = NULL;

User currentuser = (User) pumaprofile. getcurrentuser ();

Currentusername = currentuser. getname ();

Out. Print (currentusername );

%>

 

Author: Zheng Wenping has been engaged in IBM WebSphere Portal Project Implementation for eight years and has more than 40 projects with over five months of experience based on IBM portal. If you have any technical or non-technical questions, contact the author via MSN: zhengwp@cn.ibm.com or email zhengwenping@126.com for help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.