home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-05 | 3.5 KB | 128 lines |
- /**
- * CustomerInfo: A Java class that demonstrates accessing form variables, cookies, etc. with
- * the Java ASP Component Framework.
- */
-
- package IISSample;
-
- import aspcomp.*;
-
-
- public class CustomerInfo
- {
- private static final String INTERNAL_ERROR_MSG =
- new String("Internal error condition detected.");
-
- public boolean checkIfRegistered()
- {
- Request request = AspContext.getRequest();
- Response response = AspContext.getResponse();
- CookieDictionary cookDict = request.getCookies();
- Cookie c = null;
-
- try
- {
- c = cookDict.getCookie("CustInfo");
- }
-
- catch (ClassCastException cce)
- {
- response.write(INTERNAL_ERROR_MSG);
- throw new RuntimeException();
- }
-
- String strCookieValue = c.getValue();
-
- if (!strCookieValue.equals(""))
- {
- // The customer has registered before.
- return true;
- }
- else {
- // The customer has NOT registered before.
- return false;
- }
- }
-
- public boolean processForm()
- {
- Request request = AspContext.getRequest();
- Response response = AspContext.getResponse();
-
- if (request.getTotalBytes() == 0) {
- // No data here -- make the customer enter it
- return false;
- }
-
- CookieDictionary cookDict = request.getCookies();
- RequestDictionary form = request.getForm();
- Cookie cookCust = null;
-
- try
- {
- cookCust = cookDict.getCookie("CustInfo");
- }
- catch (ClassCastException cce)
- {
- response.write(INTERNAL_ERROR_MSG);
- throw new RuntimeException();
- }
-
- // Note: could return false if mandatory fields
- // aren't present
- cookCust.setItem("Prefix", form.getString("Prefix"));
- cookCust.setItem("FName", form.getString("FName"));
- cookCust.setItem("MName", form.getString("MName"));
- cookCust.setItem("LName", form.getString("LName"));
- cookCust.setItem("Suffix", form.getString("Suffix"));
- cookCust.setItem("Addr1", form.getString("Addr1"));
- cookCust.setItem("Addr2", form.getString("Addr2"));
- cookCust.setItem("AptNo", form.getString("AptNo"));
- cookCust.setItem("City", form.getString("City"));
- cookCust.setItem("State", form.getString("State"));
- cookCust.setItem("ZIP", form.getString("ZIP"));
- cookCust.setItem("Birth", form.getString("Birth"));
- cookCust.setItem("SocSec", form.getString("SocSec"));
-
- return true;
- }
-
- public String getFullName()
- {
- Request request = AspContext.getRequest();
- Response response = AspContext.getResponse();
- CookieDictionary cookDict = request.getCookies();
- RequestDictionary form = request.getForm();
- Cookie cookCust = null;
-
- try
- {
- cookCust = cookDict.getCookie("CustInfo");
- }
-
- catch (ClassCastException cce)
- {
- response.write(INTERNAL_ERROR_MSG);
- throw new RuntimeException();
- }
-
- // Note: Framework returns an empty string if the item isn't
- // found in the cookie
-
- String Prefix = cookCust.getItem("Prefix");
- String FName = cookCust.getItem("FName");
- String MName = cookCust.getItem("MName");
- String LName = cookCust.getItem("LName");
- String Suffix = cookCust.getItem("Suffix");
-
- String fullName = Prefix + (Prefix.equals("") ? "" : " ") +
- FName + (FName.equals("") ? "" : " ") +
- MName + (MName.equals("") ? "" : " ") +
- LName + (LName.equals("") ? "" : " ") +
- Suffix;
-
- return(fullName);
- }
-
- }
-