This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Error using getParameterValues method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "Error using getParameterValues method " Watch "Error using getParameterValues method " New topic

Error using getParameterValues method

Scott Updike
Ranch Hand

Joined: Feb 16, 2006
Posts: 92
I have an issue that is probably more in line with a general Java question, but I'm writing a small servlet app and thought I would start here. I have a screen where people can select items to delete and if they don't select anything, I get a java.lang.NullPointerException error. Is there any way to test if my array variable deleteNames is null or not? In looking at the API, I know that if one element is returned, then the array length is equal to 1, but I don't know how to test the length if the original parameter was null.

I'm sure this is a simple thing to do, but I can't seem to find the right way to test if the array is populated or not.

My code snippet is below.

Thanks in advance.



String[] deleteNames = request.getParameterValues("deleteitems");
try {
Connection conn1 = (Connection) getServletContext().getAttribute("dbconn");
PreparedStatement stmt = conn1.prepareStatement("delete from baissue where issue_name = (?)");
PreparedStatement stmt1 = conn1.prepareStatement("delete from issue_comments where issue_name = (?)");

for (int i=0; i<deleteNames.length;i++) {
//Delete Comments
//Delete Issue

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Or if there's nothing to be done when no values are selected, you could try:

[ June 20, 2006: Message edited by: Dave Wingate ]

Fun programming etcetera!
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Error using getParameterValues method
It's not a secret anymore!