Can you show me the code of the page where your text field is located.
Have you set the default value for your text field to a blank string i. e. ("").
In that case the check for (!= null ) would fail even if your text field was blank. You would have to check for blank string in that case like this :-
if((! request.getParameter("UserName").equals(""))) {
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
Thats strange the NullPointerException would be thrown only in case request.getParameter("UserName")
returned NULL, but in your first post you had said request.getParameter("UserName") != null evaluated to true for all cases.
Try the following condition:-
if ((request.getParameter("UserName")!=null ) && (! request.getParameter("UserName").equals(""))) {
It should accommodate both conditions when you get a blank as well as when you get a null.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
There is your problem
<input type="text" name="UsrName" maxlength="15" size="15"/>
Check the Spelling of the name given to the field, you have give"UsrName" it should be "UserName".
But it should not enter the if block as the condition ( (request.getParameter("UserName")!=null ) )still evaluates to false.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
eventhought.... same thing!
i am really confused!
Have you tried by changing the name of the field from "UsrName" to "UserName". Next show us your servlet code and why you feel that the code inside the "if" block is getting executed.
Note when pasting your code use[code=java] for java code and [code=html] for HTML, it provides syntax highlighting.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
Ok.. What was the output when you replaced
if (request.getParameter("UserName")!=null)
with the following condition:-
if ((request.getParameter("UserName")!=null) && !(request.getParameter("UserName").equals(""))) {
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
In Java null and "" are not the same thing.
null is the actual universal NULL, i. e. nothing.
On the other hand "" is a blank String object.
If an object is "null" calling any method on it would give you a NullPointerException, hence we need to first check for null and only after that we check if the String is "blank".
"null" I assume is returned when the parameter is not present at all in the request (which is not your case), but you had mentioned encountering a NullPointerException earlier, thats why I recommended both the conditions for your case.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
well if the problem has been solved it would be appreciated if you mark this thread as solved.
stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154