The moose likes JSP and the fly likes curious case of JSP page passing empty string,instead of passing null value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSP
Reply Bookmark "curious case of JSP page passing empty string,instead of passing null value" Watch "curious case of JSP page passing empty string,instead of passing null value" New topic
Author

curious case of JSP page passing empty string,instead of passing null value

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 117
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 also when I directly go for hello.jsp it throws NullPointerException.

I am unable to make head and tail of the execution. Please help me.

Anil Deshpande

This message was edited 1 time. Last update was at by Anil Deshpande



Anil Deshpande
SCJP 1.5, SCWCD 1.5
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3362

.... 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?

And also when I directly go for hello.jsp it throws NullPointerException.

That's because you don't have a request parameter called "userName".

This message was edited 1 time. Last update was at by Vijitha Kumara



SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 117
Don't you think, it is wrong. When I am not entering anything in the text feild, I expect it to be a null value. not a empty String with length=0.

I will never be sure whether to check for empty string or handle NullPointerException.

Or may be I will have to check both conditions............

This message was edited 1 time. Last update was at by Anil Deshpande

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3362

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
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.

If that is the case then no problem,

thanks a lot
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3362

Anil Deshpande wrote:So will it defnitly return empty String in case i don't enter anything in text feild.


Yes. It should.
 
 
subject: curious case of JSP page passing empty string,instead of passing null value
 
developer file tools