Dean
Dean

Reputation: 8988

Are empty fields in form of JSP null or ""?


When a form is passed in to a servlet are empty fields "" or null? So for example in a form where you have First name as a field and last name as a field
Dean - First Name
- Last Name
So what is it registered as in the servlet?
Thanks in Advance
Dean

Upvotes: 4

Views: 3682

Answers (3)

David R
David R

Reputation: 11

It also depends on the server. JBoss will give you empty Strings, but WebSphere will give you null. It's a real PITA. I'm sure there's some standard out there that says one way or another (my money would be on JBoss being the correct implementation) but you should code for both possibilities.

Upvotes: 1

Adam Crume
Adam Crume

Reputation: 15834

I think it's up to the browser, but in most cases it will be null. You should still allow for both cases.

Edit:

As noted in the comments, in most cases it will be the empty string.

Upvotes: 0

BalusC
BalusC

Reputation: 1109072

Simple: If the parameter name is present, but value not, then it's empty. If the parameter name is absent as well, then it's null. You normally give fields a name, so it's present as request parameter and empty fields will be just come in as empty string.

Upvotes: 4

Related Questions