Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.... 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".
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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............
 
Vijitha Kumara
Bartender
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3973
24
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anil Deshpande wrote:So will it defnitly return empty String in case i don't enter anything in text feild.


Yes. It should.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!