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
views:
81answers:
3
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
2010-06-28 21:31:02
It's certainly not up to the browser.
BalusC
2010-06-28 22:00:15
@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
2010-06-29 04:58:38
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
2010-06-29 12:02:47
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
2010-06-29 12:47:16
+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
2010-06-28 21:58:04
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
2010-10-06 13:07:15
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
2010-10-06 14:18:10