views:

81

answers:

3

Hi,
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

A: 

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.

Adam Crume
It's certainly not up to the browser.
BalusC
@BalusC: I beg to differ. It is up to the browser whether or not to submit empty text fields, and the value will be null if the field is not submitted and the empty string otherwise. http://www.w3.org/TR/html4/interact/forms.html#h-17.13.2 "If a control doesn't have a current value when the form is submitted, user agents are not required to treat it as a successful control."
Adam Crume
I've done webdev over a decade and I haven't seen a browser yet which omits the parameter name when the parameter value is empty, so it's certainly not "in most cases it will be null".
BalusC
You're right, now that I think about it. I'm a long time web developer too, but I've been in school the past year, and I guess I'm rusty.
Adam Crume
+2  A: 

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.

BalusC
Thanks i was a bit unsure on the comment about the browser
Dean
A: 

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.

David R
This is a **bug** in Websphere. Just install the most recent fixpack. This is described in [APAR PK10162](http://www-01.ibm.com/support/docview.wss?uid=swg1PK10162).
BalusC