Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2009, 06:12 PM
Authorized User
Points: 101, Level: 2
Points: 101, Level: 2 Points: 101, Level: 2 Points: 101, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old January 22nd, 2009, 09:31 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
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.]
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:36 AM.


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