Solved

JSP Question - URGENT

Posted on 2001-08-04
4
186 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Way to decrease size of apk file 9 109
iterator/ListIterator approach 17 54
ejb entity bean example issue 2 27
swing controls 2 23
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

733 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