Solved

capture check-box value.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now