Solved

capture check-box value.

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Clear browser cache on site login, is it possible? 3 27
maven j2ee examles 2 55
iterator/ListIterator approach 17 27
jsp login check 12 31
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

773 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