Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

capture check-box value.

Posted on 2004-04-19
3
Medium Priority
?
1,417 Views
Last Modified: 2007-12-19
How can i capture check-box value from jsp to my servlet.

Initialy on my jsp page, the check-box was not checked. But i cam calling the servlet's constructor when the JSP was shown.

abc.jsp
=====
..
..
  OBScrCCFG3000 theOb =  new OBScrCCFG3000(request);
..
..


abc.java
======
..
..
  public OBScrCCFG3000(HttpServletRequest req) {

        String transaction[] = req.getParameterValues("transaction_category");

        ArrayList al_transaction = null;

       if (transaction.length>0){

       for (int i=0; i<transaction.length;i++){
            al_transaction.add(i,transaction[i]);
        }
        System.out.println("size"+al_transaction.size());

       }
    }
..
..

When i call the abc.jsp. it's show me the transaction is null, thus give me null pointer exception. :-( How can i sovel this?

0
Comment
Question by:xman19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 600 total points
ID: 10865394
if no checkboxes are checked then i think it will be null, and you should deal with it:

  public OBScrCCFG3000(HttpServletRequest req) {

        String transaction[] = req.getParameterValues("transaction_category");

        ArrayList al_transaction = null;

       if (transaction!=null && transaction.length>0){

       for (int i=0; i<transaction.length;i++){
            al_transaction.add(i,transaction[i]);
        }
        System.out.println("size"+al_transaction.size());

       }
    }
0
 

Author Comment

by:xman19
ID: 10865422
:-)
0
 
LVL 7

Expert Comment

by:searlas
ID: 10867457
You have another NullPointerException problem, which objects has not fixed, al_transaction is null, and will cause a NPE when you attempt to call 'add' on it (and size() if it got that far)

public OBScrCCFG3000(HttpServletRequest req) {
  String transaction[] = req.getParameterValues("transaction_category");

  ArrayList al_transaction = new ArrayList();  
  for ( int i=0; transaction != null && i < transaction.length; i++ ) {
    al_transaction.add(i,transaction[i]);
  }

  System.out.println("size"+al_transaction.size());
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question