Solved

JSP Question - URGENT

Posted on 2001-08-04
4
181 Views
Last Modified: 2010-03-31
Ok, the following is my question.  Say I have a class implementing a tag.  This tag has two attributes, both correctly defined in the tld and correctly used in the JSP.  If the class implementing the class has a method like this:

public String getFirstAttr() {
 return firstAttr + getSecondAttr();
}

If we assume everything is correctly implemented, is it possible for getFirstAttr to return the value of firstAttr concatenated with null instead of the value provided for secondAttr?

Please respond quickly.

John Rayburn
0
Comment
Question by:Laminamia063099
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
black earned 300 total points
ID: 6352552
yes if getSecondAttr() returns null and firstAttr is equal to "hello" you'll get the following string:
hellonull
basically the + operator when used with strings will convert any null reference to the string "null" and that string literal will be used.
It might be best if you did
public String getFirstAttr() {
  if(getSecondAttr == null) {
    return firstAttr;
  }
  return firstAttr + getSecondAttr();
}

that way the string "hello" will be returned instead of "hellonull"
0
 
LVL 3

Author Comment

by:Laminamia063099
ID: 6356505
Notice, I mention that getSecondAttr returns null "instead of the value provided for secondAttr". If secondAttr is not null, null would not be returned, correct?

John
0
 
LVL 3

Expert Comment

by:black
ID: 6357772
yes, if the getSecondAttr method returns a non null value then you will not get null concatenated.
0
 
LVL 3

Author Comment

by:Laminamia063099
ID: 6357818
Thanks.  I was reading a book passage that was incorrect and I wanted a second opinion!

John
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now