Wrox Programmer Forums
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2009, 06:12 PM
Authorized User
 
Join Date: Jun 2007
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop Question

I have 4 check boxes on a form.

name= "box1" "box2" "box3" "box4" respectively

I am passing all 4 to another jsp page and doing a getParameter for each of them.

without having to write a lot of if statements, I need to know which boxes are checked so that i can add them to a string for an mysql query.

anyway to loop through them?

thanks
 
Old January 22nd, 2009, 09:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Code:
for ( int i = 1; i <= 4; ++i )
{
    string value = request.getParameter("box" + i);
    if ( value ???? what condition are you looking for ??? )
    {
        ...
    }
}
One thing we added early on to a Utility class (bean) were methods safeGetParameter(request,name) and safeGetIntParameter(request,name) and then used try...catch in those methods to ensure that we handled null and non-numeric values in predictable ways, as appropriate. [names are obviously up to you...and our methods were static, so we had to keep passing the Request object...might be better to always init the bean on the page by passing Request and Response to it so you don't have to pass them as arguments.]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop question??? RinoDM Javascript 1 May 13th, 2008 07:35 PM
Question on do while loop savoym Java Basics 2 May 3rd, 2007 05:56 AM
Sentinel Loop Question JMOdom C# 3 April 12th, 2007 01:19 PM
Do While Not Loop Question hcweb Classic ASP Basics 3 January 12th, 2007 01:27 PM
simple loop question Adam H-W Classic ASP Basics 2 July 9th, 2004 01:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.