Solved

capture check-box value.

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fisheye tool 2 124
I am having a difficulty creating a responsive Page for my website. 10 89
Can't access image with tomcat/html 6 114
withoutString  challenge 40 222
A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 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