Solved

capture check-box value.

Posted on 2004-04-19
3
1,414 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 150 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
In this blog we highlight approaches to managed security as a service.  We also look into ConnectWise’s value in aiding MSPs’ security management and indicate why critical alerting is a necessary integration.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

707 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