curious case of JSP page passing empty string,instead of passing null value
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
posted
0
I am facing this peculier case. I have written two files inde.jsp and hello.jsp. Index basically passes a trribute userName to hello.jsp.
See the code
index.jsp:
hello.jsp:
When I start with index.jsp. and don't enter anything in textfeild, I am sending a empty string to hello.jsp. When I remove the commented line at it prints "User name is 0". Instead of throwing NullPointerException. Is this problem some vendor specific thing.
.... and don't enter anything in textfeild, I am sending a empty string to hello.jsp. When I remove the commented line at it prints "User name is 0" ....
What's wrong with it? What's the length of an empty String variable?
Anil Deshpande wrote:I will never be sure whether to check for empty string or handle NullPointerException.
Or may be I will have to check both conditions............
What ever user enters there you'll get as a String (empty or not). It's up to you to decide what you want to do with that value.
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
posted
0
What ever user enters there you'll get as a String (empty or not).
So will it defnitly return empty String in case i don't enter anything in text feild.