Forums Register Login

NPE with if

+Pie Number of slices to send: Send
i've this form that displays my blog's content inside a textarea; the form also has two submit buttons, one for update and the other for delete.
inside my servlet i've this code:

if i try with just one if (i mean the other if is commented) all works, but if i have both ifs uncommented, i get that NPE

how can i solve this?

TiA
+Pie Number of slices to send: Send
I assume the NPE is because the parameter being passed is EITHER "editarBlog" OR "eliminarBlog", depending on what action you are doing?

If so, the easiest way around the problem is to check that the "editar" and "eliminar" variables are not null before checking for equality.

E.g.
+Pie Number of slices to send: Send
A better style is to use the String first and ignore the problem with nulls.
Also, be wary of SQL that doesn't use PreparedStatements. Your code is open to SQL injection that could allow someone to do whatever they want to your data.



Dave
+Pie Number of slices to send: Send
that works, ty!
as to prepared statement, i'll work on that
thank you both
+Pie Number of slices to send: Send
 

Originally posted by miguel lisboa:
[CODE]
try {
//if (editar.equals("Editar")) {
//access.executaUpdate(sqlActualizar);
//getServletContext().getRequestDispatcher("/EditarAvulsas").forward(request, response);
//}



editar is null or access is null , path /EditarAvulsas doesnot map to a resource.
try putting the code in a catch block of Exception and look at the exception dot printStackTrace() methods output.
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 635 times.
Similar Threads
Not able to forward servlet to
redirection
ArrayList not clearing
Sending Request to Other page
Please help me in JRUN
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 19:39:37.