I think you'll start a source code contest here.
Mine stays in topic (uses a HttpServletResponse instance ;-)


Use  this one - an EmptyField exception class with an chk() static call:

public class EmptyField extends Exception {
   public EmtyField(String message) { super(message); }
   public static void chk(String toCheck, String errMessage)
   throws EmptyField
   {
     if((toCheck == null) || toCheck.equals(""))
     throw new EmptyField(errMessage);
   }
}

And use them as here:

try {
  EmptyField.chk(newfirstname, "Hey, fill in your first name!");
  EmptyField.chk(newlastname, "Oh, my god, don't you have a last name?");
  // ... other checks until the last one.
  EmptyField.chk(newphone, "Gimme your phone too!");
  // ready.
  // Here process normally, cos all fields are filled.
  ...
}
  catch(EmptyField ef)
  {
    System.err.println(ef.getMessage());

    // write message back to browser too using an HttpServletResponse
    // response instance, just to keep servlet-interest on topic.. ;-)
    response.getPrintWriter().println(
     "<FONT COLOR=#FF0000>" + ef.getMessage() + "</FONT>");
  }
  catch (SomeOtherNastyException sone)
  {
     // .. tell user to give up.
  }

-----------------------
Cezar

                AMAZING BUT TRUE ...

If all the salmon caught in Canada in one year were laid end to end
across the Sahara Desert, the smell would be absolutely awful.

On Fri, 6 Aug 1999, Sam Rose wrote:

> Help,
> I'm going crazy over this,
> I'm doing a few else if statements, but for each one i need the some
> of same lines of Java in each of the clauses, is there a way in which I
> can do this without making it look messy??
>
> e.g. this is what I've got,
>
>
> if (newfirstname.equals("")){
>    out.println("<b>You did not fill in your name</b>");
>
>  }
>  else if (newsurname.equals("")){
>    out.println("<b>You did not fill in your surname</b>");
>
>  }
>
> and I need the same bit's of java in each of them (there are more else
> if's as well)
>
>
> cheers
>
> Sam Rose
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to