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


get all checked parameters in the servlet

Posted on 2006-11-28
Medium Priority
Last Modified: 2010-04-01
Hi Experts,

I have table in a form, so each row in the table is input (type hidden) and has check box option.

When I have checked two items ( in the first and third row) and submitted , the Servlet takes the first index insert it then it gives me null Exception

so how I can go over all the table rows and see it is checked or not?

This is my Servlet method:

   boolean flag = true;
        int i = 0;
        int counter = 0;
        Controller c = new Controller();
        Vector result = new Vector();

 try {
            while (flag){
                String check = request.getParameter("checkIssue"+i);
                System.out.println("check value:------------ : "+check);
                if (check.equals("issue"+i)){
                 System.out.println("Enter after check if");  
                 int id  = Integer.parseInt(request.getParameter("index"+i));
                System.out.println("index is:"+i);
                String storekeeper = request.getParameter("userSession");
                System.out.println("userSession is: "+storekeeper);
                String empUsername = request.getParameter("username"+i);
                System.out.println("emp username is::"+empUsername);
                System.out.println("model is:"+i);
                String sn = request.getParameter("ItemSNs"+i);
                System.out.println("item sn is::"+sn);
                String cat = request.getParameter("request"+i);
                IssuedItem issuedItem = new IssuedItem();
                int isIssued = c.issueItem(issuedItem);
                }// end of if
            }// end of while
        }// end of try
   catch(Exception e){
            System.out.println("Exception runs in action issue item:---- "+e.getMessage());
            if(request.getParameter("index"+i)== null){
                flag = false;
                System.out.println("after while");
    }// end of if null;    
Question by:Sh_Rashed
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

Expert Comment

ID: 18028366
the second row checkbox return null when you call  String check = request.getParameter("checkIssue1");
So change:   if (check.equals("issue"+i)) {...
To:   if (check != null && check.equals("issue"+i)) {...

Expert Comment

ID: 18028442
Your while (flag){} loop will be infinite-loop.  You should change it to for-loop based on how many checkboxes you have.

Author Comment

ID: 18028643
I don't know How many checkboxs I have, since the table generated according to the database records .

Expert Comment

ID: 18028990
We can fix this problem by check if the hidden input box existing ot not if there always be a hidden input box with a checkbox together.

while (flag) {
    if( request.getParameter("index"+i) == null)
     String check = request.getParameter("checkIssue"+i);
     System.out.println("check value:------------ : "+check);

     if (check != null && check.equals("issue"+i)) {...

Accepted Solution

dasmaer earned 1500 total points
ID: 18031807
A small cheat I used for something like this was a javascript counter declared at the top of the generated HTML.  When a new check box is drawn by the JSP, you add a <script></script> that increments the counter each time.  If you then wanted to be super clever you could write a small javascript that'll check if all the boxes have been ticked (or whatever you;re condition is), so that you can do less checking on the server side.

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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