well, I'd like to see an example of where you'd need such a function.
You can obviously check for null with
if (variable !=null) { ...
but there are also some tricks that might help you.
when comparing Strings, start with the literal String.
i.e. use
if ("test".equals(variable)){ instead of
if
iable.equals("test")){
the first case will return false if variable is null, the second one throws an
NullPointerExc.
Also, (but this might be more controversial) I started to use the ternary ?: operator
in JSP.
instead of writing
<%if ("test".equals(variable)){%>
<%=variable%>
<%} else {%>
nothing entered
<%}%>
I use
<%=("test".equals(variable))?variable:"nothing entered"%>
OK, it might look hard to read, but the first case isn't very elegant as well, and I'm
lazy ;-)
Geert Van Damme
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Daniel Lynn
> Sent: donderdag 15 maart 2001 6:23
> To: [EMAIL PROTECTED]
> Subject: isset()
>
>
> ok, in PHP there is a command called isset(). It returns a boolean to
> tell you if a certain variable was passed to the program or not. (Helps
> eliminate those nullpointer exceptions without putting everything in
> try/catch statements) Now, I was looking for one in JSP and I'm having a
> little trouble. I think it may just be I don't know what I'm looking
> for, so if anyone would be so kind as to let me know the name of the
> function if it exists it'd be MUCH appreciated. Thank you in advance.
>
> -Daniel
>
> ==================================================================
> =========
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set
> JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets