?
Solved

JSP Question - URGENT

Posted on 2001-08-04
4
Medium Priority
?
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
black earned 1200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

800 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