[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
Author

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

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Messages: 90

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


regards

Anil Deshpande
Java always amazes me
--------------------
SCJP 1.5
SCWCD 1.5
Vijitha Kumara
Ranch Hand

Joined: Mar 24, 2008
Messages: 1978

.... 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
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Messages: 90

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


regards

Anil Deshpande
Java always amazes me
--------------------
SCJP 1.5
SCWCD 1.5
Vijitha Kumara
Ranch Hand

Joined: Mar 24, 2008
Messages: 1978

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.

SCJP 5, SCWCD 5
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Messages: 90

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

regards

Anil Deshpande
Java always amazes me
--------------------
SCJP 1.5
SCWCD 1.5
Vijitha Kumara
Ranch Hand

Joined: Mar 24, 2008
Messages: 1978

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


Yes. It should.

SCJP 5, SCWCD 5
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
IntelliJ open source