Having trouble with "While"

I'm trying to loop a nested table with data in my jsp file. I only want to go 2 times then start a new row then 2 times again and so on. I'm using while but can't find the problem. I'm fairly new to jsp and java and have used for loops for loops in the past. This is my first with "while". Anyway...here's my code. Any ideas what I screwed up?
<%@ page language="java" contentType="text/html" import="java.util.*" import="java.sql.ResultSet" %>
<%
ResultSet result = (ResultSet)request.getAttribute("result");
%>
<html>
<head>
<title><%= request.getAttribute("cat") %></title>
</head>
<body>
<table width="780" border="0" cellspacing="0" cellpadding="1">
<tr>
<%
int i = 0;
while(result.next(i))
%>
     <td>
     <table width="100%" border="1" cellspacing="0" cellpadding="2">
          <tr>
          <td colspan="2"><%= result.getString("catalog.PRODNAME") %></td>
          </tr>
          <tr>
          <td rowspan="3"><a href="<%= result.getString(catalog.PIC") %">" target="_blank"><img src="<%= result.getString("catalog.THUMB") %>" border="0"></a></td>
          <td><%= result.getString("catalog.DESC") %></td>
          </tr>
          <tr>
          <td><%= result.getString("catalog.NOTES") %></td>
          </tr>
          <tr>
          <td><p>?</p></td>
          </tr>
          <tr>
          <td><%= result.getString("catalog.ITEMNO") %></td>
          <td>?</td>
          </tr>
          <tr>
          <td>$<%= result.getString("catalog.PRICE") %> - <%= result.getString("catalog.UOM") %></td>
          </tr>
          </table>
     </td>
     <%
     if(i%2 ==1 && i < result.size -1)
     %>
     </tr><tr>
     <% }
     else if(i%2 ==0)
     { %>
     <td>?</td>
     <% }      //end if
}     //end while
%>
</tr>
</table>
</body>
</html></a>

Hi,
This might help you...
<%@ page language="java" contentType="text/html" import="java.util.*" import="java.sql.ResultSet" %>
<%
ResultSet result = (ResultSet)request.getAttribute("result");
%>
<html>
<head>
<title><%= request.getAttribute("cat") %></title>
</head>
<body>
<table width="780" border="0" cellspacing="0" cellpadding="1">
<tr>
<%
int j = 0;
while(result.next())
{   //create a main table to hold two tables for two products per row
     <table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
<tr>
          do //this will create two tables within the main table for two products. j is used to check that.
          %>
               <td width="50%">
               <table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">
               <tr>
               <td width="50%"><%= result.getString("catalog.PRODNAME") %></td>
<td width="50%"> </td>
</tr>
<tr>
<td width="50%" rowspan="3"><a href="<%= result.getString(catalog.PIC") %">" target="_blank"><img src="<%= result.getString("catalog.THUMB") %>" border="0"></a></td>
<td width="50%"><%= result.getString("catalog.DESC") %></td>
</tr>
<tr>
<td width="50%"><%= result.getString("catalog.NOTES") %></td>
</tr>
<tr>
<td width="50%">?</td>
</tr>
<tr>
<td width="50%"><%= result.getString("catalog.ITEMNO") %></td>
<td width="50%">?</td>
</tr>
<tr>
<td width="50%">$<%= result.getString("catalog.PRICE") %> - <%= result.getString("catalog.UOM") %></td>
<td width="50%"> </td>
</tr>
</table>
</td>
               <%
                    j++;
     }while ((j < 2) && result.next()); //continue till two products are created within one row
     if (j == 1) //if the last row has only one product, create a blank table for the second product
          %>
               <td width="50%"></td>
               <%
          else
               j = 0; //reset j and close the main table
          %>
               </tr>
          </table>
               <%
          %>
</body>
</html>
I didn't compile the code. You may have to fix some part of it.
The program tries to create a table with two columns. Each column will hold a table for the product, so that you will get two products per row.
The program tries to stack one table after the other, means each time a new table is created for holding two products. This could be very easily fixed by moving the table tag outside the while loop.
Good luck!
Rajesh</a>

Similar Messages

  • I am having trouble with my speakers not working while online in particular on windows.My audio works when playing audio files

    I am having trouble with my speakers not working while online particular on facebook. My audio works when playing audio files.

    Hi,
    Did it happen all the time or sometime?
    Please check online browser status:
    Click Volume icon in the taskbar, click Mixer link button as below:
    If it's fine, follow this guide to run troubleshooter to detect and fix the issue:
    Tips for fixing common sound problems
    http://windows.microsoft.com/en-in/windows/tips-fixing-common-sound-problems#tips-fixing-common-sound-problems=windows-7
    Meanwhile, this similar thread also could be referred:
    https://social.technet.microsoft.com/forums/ie/en-US/a4a1cfe5-93a5-4c0b-9bf6-f7db0304f2ba/no-sound-on-youtube-or-any-other-webpage
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Having trouble with momentary delays while scrolling and typing, new problem that seems to be getting worse every day. Mouse?

    Having trouble with momentary delays while scrolling and typing.  It's a new problem that seems to be getting worse every day. Mouse? Internet connection? It's driving me nuts!

    Hi
    Did you find a solution ?
    I have the same problem on my iPhone 4

  • Having trouble with freezing starting and stoping while syncing to i-pod

    Having trouble with itunes freezing while syncing to i-pod

    I have a Macbook with Tiger, and OS x 10.4.  I had to install a new hard drive.
    Run Disk Utility   /Applications/Utilities
    First, go to your Apple menu then click Software Update...
    If no updates are available, check the startup disk using Disk Utility.
    Using Disk Utility to verify or repair disks

  • I have a factory unlocked 4s I'm haveing trouble with the mms withI have a  straight talk I'm useing the sim card swap with tmoblil sim card I'm following the insructions but it works for a while and then its gone. I've set the settings at least ten times

    I have a factory unlocked 4s I'm having trouble with the mms with straight talk I've been useing the sim swap system with tmobile i have put the settings in five times. The setting won't stay it works for a while and then it's gone. I'm not in a good coverage area but when i put the settings in i make sure i'm getting a good signal or near wifi. any suggestions would be great.

        Congrats on your recent upgrade actionkatie! I am sorry to learn of the difficulties you are experiencing with your Samsung Galaxy S4. Let's get to the bottom of this because we want you to love your phone.
    I understand you have done all necessary troubleshooting steps that should have enabled you to send messages to iPhone users without them having to disable iMessage. Have you tried contacting Apple Support regarding the inability to send a text message to iPhone users? Apple can be reached at (800) 275-2273.
    In addition, do you get a certain error message when your WiFi stops working? Have you verifed that Auto Switch network is disabled? To disable this setting simply to go Settings > Wi-Fi > Tap the Menu Key(to the left of the home button) > Select Advanced and it is called `Auto network switch. If you are still experiencing difficulties, please feel free to reach out to us for further assistance.
    Thank You,
    MichelleL_VZW
    VZW Support
    Follow us on Twitter @VZWSUPPORT

  • I am having trouble with my bluetooth skipping while its playing music from my Itunes music...I thought that this was an antiquated problem with the new technology?

    I am having trouble with the music from my bluetooth "skipping" on my IPhone 5.  I thought that this was an antiquated problem with the new technology.  It's very frustrating to purchase all of this music and expect great sound and playability and get "skipping".  Any ideas on how to resolve this issue?

    Does the issue occur when listening to the media using the speaker or wired headphones?  If it does, the issue is with the media itself.
    If it does not, it's likely a bad connection or interference.

  • I am having trouble with my Mac Mini's ethernet connection.   Defining a new network interface shows no ethernet adaptor.  Reloading SL from DVD repaired.  But SL update lost ethernet again.  Will Lion Fix?

    I am having trouble with my mac mini ethernet.  It had been working for weeks after an update to SL 10.6.8.
    Once it went out and i repaired it by defining a new connection from System Preferences ->Network->(left panel service, +).
    But yesterday, after a power up.  my ethernet was not working again. I tried this old trick to repair it, but the interface choices
    listed for '+' a new service did not include Ethernet any more.  And the Utilities->System Profiler->Ethernet Cards shows
    no ethernet available.
    As a last ditch effort i reloaded my original SL from DVD.  (I think it was version 10.6.4 but i could be mistaken on the version).
    The ethernet worked!  But KeyNote wasn't going to work because apparently the version i purchased depends on 10.6.8.
    So I upgraded again to SL 10.6.8 (Plus some other updates like AirPort which i don't use).
    Now the Ethernet is not working again.  I see the same symptoms as before with the Ethernet seeming not installed.
    Is this a problem seen by others?
    Would going to Lion fix the problem?
    Could AirPort actually be the culprit and not SL?
    If i stay with my original SL, would i need to repurchase a version of KeyNote for the older version of SL?

    Have you reset the SMC?
    Shut down the computer.
    Unplug the computer's power cord.
    Wait fifteen seconds.
    Attach the computer's power cord.
    Wait five seconds, then press the power button to turn on the computer.
    While you're at it, resetting the PRAM won't hurt anything and 'might' help is SMC reset didn't work (PRAM does some port control):
    Shut down the computer.
    Locate the following keys on the keyboard: Command, Option, P, and R. You will need to hold these keys down simultaneously in step 4.
    Turn on the computer.
    Press and hold the Command-Option-P-R keys. You must press this key combination before the gray screen appears.
    Hold the keys down until the computer restarts and you hear the startup sound for the second time.
    Release the keys.
    Something else you might try .... you don't say how you're updating to 10.6.8, however, if you're using Software Update, you might try downloading the 10.6.8 combo update, which contains all updates to 10.6. Sometimes, Software Update doesn't work quite right, and installing the combo update fixes that. Download the update from Apple's download site at http://support.apple.com/downloads/ , using Disk Utility repair permissions, apply the combo update, then repair permissions again.

  • Is PE10 compatible with Windows 8? Having trouble with the organizer.

    Is PE10 compatible with Windows 8? Having trouble with the organizer

    It does sound very Watch Folders-esque, however, it seems strange that there are many folders involved. Are all the folders under a single parent folder perhaps? If so, you could try renaming or moving that folder. Additionally, to clarify, all 60 files are images, correct?
    Additionally, you can try creating a new catalog, just to see if that lets you in. Hold down the Shift key while launching the Organizer. If you get the timing right, the Catalog Manager will appear.

  • Having trouble with image processor...help please!

    HI there...First off I just bought a new iMac and haven't a clue what I'm doing so my problem could be related to that.  While I'm waiting for Adobe to transfer over my platform I downloaded the trial of CS5 Extended to get me started.  I'm having trouble with the image processor...I choose file/scripts/image processor...the dialog box comes up and I choose use open files and then try and choose the folder I want to save them in.  I choose my folder and hit run and it keeps telling me specify folder destination.  I can't for the life of me figure this out...what am I doing wrong?  It always worked fine for me on my PC and CS3.  I can't handle saving each image individually in the new folder...
    Thanks!!

    I haven't renamed anything as far as I know.  I made a new folder when I hit Folder option and it's highlighted as well as the path shows up in the processor box.  Just when I choose run it tells me to specify a folder.  The only thing I can think of is that maybe something messed up b/c I'm copied the files and folders over from my PC but it let me save as on the mac.  Also the folder I'm choosing to put them in is on the Mac harddrive.  IDK...

  • Having trouble with my PHP code. Appers to get stuck on a white page.

    HI all,
    I have just began having trouble with my PHP code. Was working before and haven't made any changes to the code since last time it worked.
    What happens is after the form is submitted it goes to a white page (no text just all white page) and in the address bar it has the path for my php page. what supposed to happen is either it goes to a success page or a error page.
    I've had a problem where the info entered is correct but was directed to the error page. i managed to fix that issue but i am puzzled what is happening to my php page now.
    Mind you that i didn't write this code i just took over the responsiblities of this website and i am hopping that its a quick fix.
    I appreciate any help you could give me. Thank you.
    CODE:
    <?php
       $to = '[email protected]';
          $from = '[email protected]';
            //Make sure we have some info posted from the form...
            if (isset($HTTP_POST_VARS)){
                //Clear the body of the message to be sent
                $body = '';
                //go through all POSTed variables sent
                while (list($key, $value) = each($HTTP_POST_VARS)){
        if($key <> "Submit" && $key <> "submit") {
         $body .= $key . ' = ' . $value . "\r\n"; 
                //Now building mail headers.....
                $headers = "From: ".$from."\r\n";
                //Mail message
                $success = mail($to, "Email Club" . date("m/d/Y"), $body, $headers);
       // CURL stuff.....
       $ch = curl_init();
       curl_setopt($ch, CURLOPT_FAILONERROR, 1);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($ch, CURLOPT_TIMEOUT, 4); //times out after 4s
       curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                 if ($success){
        //readfile('http://www.lvpaiutegolf.com/thankyou.html');
        curl_setopt($ch, CURLOPT_URL,"http://www.lvpaiutegolf.com/thankyou.html");
        header("Location:http://www.lvpaiutegolf.com/thankyou.html");
                else{
                 // readfile('http://www.lvpaiutegolf.com/error.html');
         curl_setopt($ch, CURLOPT_URL,"http://www.lvpaiutegolf.com/error.html");
         header("Location:http://www.lvpaiutegolf.com/error.html");
       // Output
       //$result=curl_exec ($ch);
       //curl_close ($ch);
       //echo $result'";
    ?>

    Insert the install disk and boot from it. Use disk utitlity to repair your drive and check for errors (report any errors back here) then reinstall the os. This should not erase your data.

  • I am having trouble with a form, won't tab to 2nd page...

    I am having trouble with a form I created in Acrobat Pro 10. I created tabs etc, they all work wonderfully in Adobe, but once I uploaded it onto the web-based program for other users, the tabs only work  on page 1, I have to click on page 2 to keep tabbing through.  It won't tab into it.  Any advise?  Also, when the users open it it opens in the web.

    1. The library is separate from the application, so re-installing shouldn't cause an issue with the actual photos. But it would be foolhardy in the extreme to do anything without first backing up.
    2. Often these issues are caused by a damaged Library, so reinstalling doesn't change much.
    FWIW
    To re-install iPhoto
    1. Put the iPhoto.app in the trash (Drag it from your Applications Folder to the trash)
    2a: On 10.5:  Go to HD/Library/Receipts and remove any pkg file there with iPhoto in the name.
    2b: On 10.6: Those receipts may be found as follows:  In the Finder use the Go menu and select Go To Folder. In the resulting window type
    /var/db/receipts/
    A Finder Window will open at that location and you can remove the iPhoto pkg files.
    3. Re-install.
    If you purchased an iLife Disk, then iPhoto is on it.
    If iPhoto was installed on your Mac when you go it then it’s on the System Restore disks that came with your Mac. Insert the first one and opt to ‘Install Bundled Applications Only.
    If you purchased it on the App Store you can find it in your Purchases List.
    Alternative approach:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • I'm having troubles with Mail. Some mails (in particular to gmail addresses) are not sent.

    I'm having troubles with Mail. Some mails (in particular to gmail addresses) are not sent. When sending an email, Mail apparently works for a while but does'nt sent anything. I repeated sending the mail with the same result and 2 or more mails in the draft folder. Yesterday I discovered that the mail had been sent 4 times!. Now I have the same problem: the mail has not been sent, it appears in the draft folder, I try to delete it but the mail remains in the draft folder. This happens after updating to Mac OS X 10.7.2 and migrating to iCloud.
    I have MacBook 2 Ghz Intel Core 2 Duo, 4 Mb ram memory, Mac OS X Lion (10.7.2).

    If those music are greyed out in iTunes on your laptop, are you able to play the music? If you cannot, it means that you probably deleted the mp3 file or moved it to another location where iTunes can no longer find. If they are greyed out on iTunes and cannot play them, I would just right click and delete it. Then re-sync with your iPad.

  • Hi, having trouble with my iMac on startup. Background screen appears, but no icons,

    Having trouble with my iMac- on startup, the background screen appears, but no icons. The spinning beach ball appears for quite a long while, then when the icons finally come up, when I open a finder window, the only icons to appear are the Network and Macintosh HD icons. I've tried to repair disk permissions: this came up with heaps of errors, which it then fixed, but the original problem remains.
    Any suggestions on how to fix this?
    thanks

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins and log in as Guest. For instructions, launch the System Preferences application, select Help from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box. Same problem(s)?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    Note: If you’ve activated “Find My Mac” or FileVault in Mac OS X 10.7 or later, then you can’t enable the Guest account. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Same problem(s) in safe mode?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • Having trouble with my  email from google

    Having trouble with my email from gmail, both on my iPhone and on my iMac. It keeps asking to validate my password and e en after that it won't work. Does anyone know what to do?

    Hey Florian Fangohr,
    Thanks for the question. I understand you are experiencing issues with Mail in OS X Mavericks. Base on the symptoms you provided, the following article may help to resolve your issue:
    Mail (Mountain Lion): If your password is not saved
    http://support.apple.com/kb/PH11775
    If you click “Save password” in a dialog in Mail but still have to enter your password, there are a couple of things you can try.
    - Open Keychain Access, and then locate and delete the mail account password item.
    While in Keychain Access, you can also choose Keychain Access > Keychain First Aid to verify and repair keychain settings.
    - Open Disk Utility, and then select the volume (for your hard disk or disks) in the list of disks and volumes. Click First Aid and then click Verify Disk. If necessary, click Repair Disk. Then send yourself a test message.
    Note: The same steps apply for OS X Mavericks
    Thanks,
    Matt M.

  • Having trouble with throws...

    Hey there.
    I'm fairly new to java so bear with me here.
    I'm having trouble with a program that, in short, reads from a file.
    Let me shorten a show the code to you...
    //main opens up and in a bit we get to...
    if (loginVerify())
    //and the if continues.
    fileIn.close();
    //main ends
    public boolean loginVerify() throws IOException
         openIn(); //Checks for validity - It's a long story why I //didn't just put the code in loginVerify(). I //don't think it should matter.
    String str = verifyLog(); //Does the actual reading
         str = str.substring(1);
         if (str == placeHold) //Don't worry about not making placeHold,
    //I made it global for testing reasons.
              return true;
         else
              return false;
    private String verifyLog() throws IOException
         String str;
         while (true)
              str = fileIn.readLine();
              if (str == null)
                   break;
              else if (str.charAt(0) == 1)
                   return str;
              //ADDITION OF OTHER NUMBERS
              else
                   return str = "invalid";
    private void readIn() throws IOException
         BufferedReader console =
    new BufferedReader(new InputStreamReader(System.in));
    openInputFile(fileName);
    if (fileIn == null)
    System.out.println("*** Can't open " + fileName + " ***");
    return;
    private static void openInputFile(String fileName)
    try
    fileIn = new BufferedReader(new FileReader(fileName));
    catch (FileNotFoundException e)
    So it's fairly simple. It checks for validity and then reads lines until it finds one with the first char as '1' when it finds it, it reads the rest of the line off.
    The error I'm getting is as follows: Exception java.io.IOException must be caught, or it must be declared in the throws clause of this method.
    I've added throws IOException to them in attempts to fix the error but to no avail. I've tryed putting the catch in different spots... again, doesn't work.
    I'm using codewarrior IDE version 5. I'm fairly sure it's the newest. I installed Java SDK 1.3 with codewarrior originally but I installed 1.4.1 recently.
    If you need to see anything else about it, please tell me. I'd be more than happy to post a little more if it'll help.
    Thanks

    Ok. I worked through a bunch of throws and now I've found one I can't seem to conquer.
    private String verifyLog()
           String str = "";
           while (true)
                try {
                str = fileIn.readLine();
                catch (FileNotFoundException g) {
                if (str == null)
                     break;
                else if (str.charAt(0) == 1)
                     return str;
                //ADDITION OF OTHER PEOPLE
                else
                     return str = "invalid";
           return str = "invalid";
      }This time the error is at the reference to readLine() and it tells me the same error as before. I have a catch set up there, don't I?
    readLine() is something I didn't create so I don't know how I'd tell it to throw an exception if I had to...
    Thanks

Maybe you are looking for