mardi 26 mai 2015

request.getParameter without checking the checkbox in UI ... Servlets (J2EE)

I have seen so many articles but never got this point. Can you explain why ?

Here is the code I do have:

HTML:

<input type="checkbox" name="mailing" /> Would you like to join our mailing list ?

SERVLET:

request.getParameter("mailing").equals("on") ? true : false; // Error if I have NOT checked the checkbox.

"on".equals(request.getParameter("mailing")) ? true : false; // No Error - Works as Expected.

What is the difference between these two ?

Aucun commentaire:

Enregistrer un commentaire