Example: UPServletExtended.java
import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import com.ibm.websphere.userprofile.UserProfile; import com.ibm.websphere.userprofile.UserProfileManager; import com.ibm.websphere.userprofile.UserProfileCreateException; import com.ibm.websphere.userprofile.UserProfileFinderException; import com.ibm.websphere.userprofile.UserProfileRemoveException; import com.ibm.websphere.userprofile.UserProfileProperties; public class UPServletExtended extends HttpServlet { public void doGet HttpServletRequest(req, HttpServletResponse res) throws ServletException, IOException { UserProfileManager manager = UserProfileManager.getUserProfileManager(); UserProfile userprofile; PrintWriter out; res.setContentType("text/html"); out = res.getWriter(); try { //try Creating the UserProfile userprofile = manager.addUserProfile("mpareene"); } catch( UserProfileCreateException e1) { try { //try finding the existing in readWrite mode userprofile = manager.getUserProfile("mpareene",true); } catch UserProfileFinderException(e) { e.printStackTrace(); return; } } userprofile.setAddress1("myaddress1"); userprofile.setAddress2("myaddress2"); userprofile.setFirstName("Pareene"); userprofile.setSurName("Mike"); userprofile.setDayPhone("555-6677"); userprofile.setNightPhone("556-6765"); userprofile.setCity("MYCITY"); userprofile.setNation("myCountry"); userprofile.setEmployer("MyEmployer"); userprofile.setFax("7823470"); userprofile.setLanguage("mylanguage"); userprofile.setEmail("MyEmail@email"); userprofile.setStateOrProvince("myState"); userprofile.setPostalCode("xxxxx"); //calling putValue ((UserProfileProperties)userprofile).putValue("name","HHHHHHH"); ((UserProfileProperties)userprofile).putValue("Date",new java.util.Date()); //Freeing resources held by userprofile manager.releaseResources(userprofile); userprofile=null; //Checking whether it updated the info try { //Getting the existing userprofile userprofile = manager.getUserProfile("mpareene",false); out.println(userprofile.getAddress1()+"<br>"); out.println(userprofile.getAddress2()+"<br>");; out.println(userprofile.getFirstName()+"<br>");; out.println(userprofile.getSurName()+"<br>"); out.println(userprofile.getDayPhone()+"<br>");; out.println(userprofile.getNightPhone()+"<br>");; out.println(userprofile.getCity()+"<br>"); out.println(userprofile.getNation()+"<br>");; out.println(userprofile.getEmployer()+"<br>");; out.println(userprofile.getFax()+"<br>");; out.println(userprofile.getLanguage()+"<br>");; out.println(userprofile.getEmail()+"<br>");; out.println(userprofile.getStateOrProvince()+"<br>");; out.println(userprofile.getPostalCode()+"<br>"); //Getting the values out.println(((UserProfileProperties)userprofile).getValue("name")+"<br>"); out.println(((UserProfileProperties)userprofile).getValue("Date")+"<br>"); out.println("Removing Values "); ((UserProfileProperties)userprofile).removeValue("name"); ((UserProfileProperties)userprofile).removeValue("Date"); out.println(((UserProfileProperties)userprofile).getValue("name")+"<br>"); out.println(((UserProfileProperties)userprofile).getValue("Date")+"<br>"); //Freeing resources held by userprofile manager.releaseResources(userprofile); } catch( UserProfileFinderException e1) { out.println("Error finding "); e1.printStackTrace(); return; } } }
See Also
Managing user profiles
User profile development options