This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
i am using following code but if condition is not working .....values are coming from previous servlet if i dont enter any value for i2 and i3 then the value of m2 and m3 will be null but statements in second and third if condition are being executed...please help me to solve this problem
Most likely m2 and m3 are NOT null; their value is probably the zero-length string.
rakhi sinha
Ranch Hand
Joined: Mar 26, 2012
Posts: 147
posted
0
Tim Moores wrote:Most likely m2 and m3 are NOT null; their value is probably the zero-length string.
but when i try to print thees values .null value is printed so what should i do for this ....i dont want to print all the three if condition .depends on values of i1,i2 and i3 entered from previous servlet
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.
Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?
There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.
rakhi sinha
Ranch Hand
Joined: Mar 26, 2012
Posts: 147
posted
0
Tim Moores wrote:That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.
Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?
There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.
i will chage variable name .but i think it is not releted to my problem ...i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values....i am confused that where am i wrong ???
Tim Moores wrote:That sounds unlikely. We don't know how you print the values, but if the value of m1 is null, then a block guarded by "if (m1!=null)" wouldn't be executed.
Your variable names are very confusing, by the way - m1, n1, o1 means nothing. Why aren't they named i1, q1, c1 to go along with the parameter names? Or, even better, have a name that actually describes what they contain?
There's no point in loading the DB driver every single time the servlet is accessed, by the way. You should move that code to the init method.
i will chage variable name .but i think it is not releted to my problem ...i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values....i am confused that where am i wrong ???
changing the names will not solve your problem... but it will mean that it is easier to read your code and understand it, and when you have to come back to maintain this code later you will understand what it is doing.
Tim Moores wrote:Most likely m2 and m3 are NOT null; their value is probably the zero-length string.
but when i try to print thees values .null value is printed so what should i do for this ....i dont want to print all the three if condition .depends on values of i1,i2 and i3 entered from previous servlet
do they actually contain the word 'NULL'?
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2407
posted
0
rakhi sinha wrote:i am printing the value of m2 amd m3 in next page by redirecting the servlet to next page only for checking their values
If you do a redirect then all your parameters will be gone, so that's not a valid test. You might want to consider using a debugger to step through the actual code that causes the problem.