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.