Example: UPServletExample.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;
//Creates a Userprofile using the new API
public class UPServlet_ReadWrite extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
PrintWriter out;
res.setContentType("text/html");
out = res.getWriter();
UserProfileManager manager = UserProfileManager.getUserProfileManager();
UserProfile userprofile;
try {
//Try creating the UserProfile
userprofile = manager.addUserProfile("bpink");
} catch(UserProfileCreateException e1) {
try {
//Try finding the existing in readWrite mode.
//Second argument indicates whether we want to get userprofile
//in read only mode or read write mode.
userprofile = manager.getUserProfile("bpink",true);
} catch(UserProfileFinderException e) {
e.printStackTrace();
return;
}
}
//Set the properties
userprofile.setAddress1("myaddress1");
userprofile.setAddress2("myaddress2");
userprofile.setFirstName("Pinkowski");
userprofile.setSurName("Ben");
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");
//Freeing resources held by userprofile
manager.releaseResources(userprofile);
userprofile=null;
//Checking whether it updated the info
try {
//Getting the existing userprofile in ReadOnly mode.
userprofile = manager.getUserProfile("bpink",false);
} catch(UserProfileFinderException e1) {
out.println("Error finding ");
e1.printStackTrace();
return;
}
//Displaying the properties of userprofile
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>");
//Freeing resources held by userprofile
manager.releaseResources(userprofile);
}
}

Using user profiles

User profile development options
Searchable topic ID:
UPServletExample_java
Last updated: Jun 21, 2007 4:55:42 PM CDT
WebSphere Application Server Network Deployment, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rprs_upservlet_example_java.html