Solved

Need Help with formatting JSP

Posted on 2004-08-18
7
328 Views
Last Modified: 2013-12-03
Hello Experts,
i have a jsp page below that has a for loop for reading in data
i am having difficulty getting the results to output in repeated rows
i think that i am placing the end of the for loop in the wrong place
to allow the rows to repeat when there is multiple data.
it works but it just looks bad
can anyone help me sort this out
it should be an easy 300 pts for yeah
unlike many of my other threads!!
Gaz :)

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;
CallableStatement cs = null;
try
{
  conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
  cs = conn.prepareCall("{Call SiteSearchQ(?, ?, ?)}");
 
  String snames[] = request.getParameterValues("SiteName");
    for( int ii=0; snames!=null && ii<snames.length; ii++ )
    {
      String siteName = snames[ii];
  //String siteName = request.getParameter("SiteName");
  //if( siteName == null ) siteName = "";
  int selCyc=Integer.parseInt( request.getParameter("SelectCyc"));
  int year=Integer.parseInt( request.getParameter("SelectYear"));
 
      //cs.setString(1, siteName );
      cs.setString(1,siteName);
    cs.setInt(2, selCyc );
    cs.setInt(3, year);
   
  ResultSet rs = cs.executeQuery();
  %>
      
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SearchRes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



</head>
<body>
<form name=Bookform Action="BookingPage.jsp" method="post">
  <table width="95%" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
      <td height="74" colspan="4" align="left" valign="bottom" bgcolor="#FFFFFF">
        <div align="right"></div>
        <div align="left"></div>
        <div align="left"></div>
        <table width="99%" height="34" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#006699">
          <tr bordercolor="#0033CC">
            <td width="245" height="20" align="center" valign="middle"> <div align="center"></div>
              <strong><font color="#000000" size="1">&nbsp;</font></strong><font color="#000000" size="1"><strong>Site
              Location</strong></font></td>
            <td width="155" height="20" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>Site
                Format</strong></font></div></td>
            <td width="83" align="center" valign="middle"> <font color="#000000" size="1">&nbsp;<strong>Prismatic</strong></font></td>
            <td width="72" align="center" valign="middle" bgcolor="#FFFFFF"> <div align="center"><font color="#000000" size="1"><strong>Illuminated</strong></font></div></td>
            <td width="67" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>CycleStart</strong></font></div></td>
            <td width="119" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"></font></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><strong>CycleEnd</strong></font></div></td>
            <td colspan="2" align="center" valign="middle"> <div align="center">
                <div align="center"><font color="#000000" size="1"></font></div>
                <div align="center"><font size="1"><strong>Book</strong></font></div>
                <font color="#000000" size="1"></font></div>
              <div align="center"></div></td>
          </tr>
          <% while (rs.next())
        { %>
          <tr bgcolor='#EEEFF3' onMouseOver="this.bgColor='#B2C4F0';" onMouseOut="this.bgColor='#EEEFF3';">
            <input name="siteId" type="hidden" value="<%=rs.getString("SiteID")%>">
            <td height="12"> <div align="center"></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><%=rs.getString("SiteLocation")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString("SiteType")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Prismatic")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Illuminated")%></font></div></td>
            <input name="cycleId" type="hidden" value="<%=rs.getString("CycleID")%>">
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleStart")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleEnd")%></font></div></td>
            <input name="bookYear" type="hidden" value="<%=rs.getString("BookYear")%>">
            <td width="120"><div align="center"><font color="#000000" size="1">
                <input type="checkbox" name="bookingsNo" value="<%=rs.getString("BookingsNo")%>">
                </font></div></td>
          </tr>
          <%} // end the while loop %>
              <%}// end the for loop %>
        </table>
        <div align="center"> </div></td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"></td>
    </tr>
    <tr valign="middle">
      <td height="21" colspan="4" align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compAddress" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">City </font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="cityName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Country</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="countryName" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Postcode</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="postCode" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Phone Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="phoneNum" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Fax Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="faxNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Email Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="emailAdd" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Category</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodCat" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Price</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="priceNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"><input type=submit name=Submit value="BookIt"></td>
    </tr>
  </table>
</form>
<%
}
    catch (Exception e)
    {
      e.printStackTrace() ;
     out.print("Exception: " + e);
        

    }
    finally
    {
     if( cs != null ) try { cs.close(); } catch( Throwable t ) { t.printStackTrace(); }
     if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
    }
%>
</body>
</html>
0
Comment
Question by:Gar04
[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
  • 3
7 Comments
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11828297
Is there any error or exception throw out?
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11828317
I think you just remove this line, I cannot see the matching for loop.

<%}// end the for loop %>
0
 
LVL 35

Accepted Solution

by:
TimYates earned 250 total points
ID: 11828572
is this any better?

-----------

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;
CallableStatement cs = null;
try
{
  conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
  cs = conn.prepareCall("{Call SiteSearchQ(?, ?, ?)}");
 
  String snames[] = request.getParameterValues("SiteName");
  %>
     
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SearchRes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



</head>
<body>
<form name=Bookform Action="BookingPage.jsp" method="post">
  <table width="95%" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
      <td height="74" colspan="4" align="left" valign="bottom" bgcolor="#FFFFFF">
        <div align="right"></div>
        <div align="left"></div>
        <div align="left"></div>
        <table width="99%" height="34" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#006699">
          <tr bordercolor="#0033CC">
            <td width="245" height="20" align="center" valign="middle"> <div align="center"></div>
              <strong><font color="#000000" size="1">&nbsp;</font></strong><font color="#000000" size="1"><strong>Site
              Location</strong></font></td>
            <td width="155" height="20" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>Site
                Format</strong></font></div></td>
            <td width="83" align="center" valign="middle"> <font color="#000000" size="1">&nbsp;<strong>Prismatic</strong></font></td>
            <td width="72" align="center" valign="middle" bgcolor="#FFFFFF"> <div align="center"><font color="#000000" size="1"><strong>Illuminated</strong></font></div></td>
            <td width="67" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>CycleStart</strong></font></div></td>
            <td width="119" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"></font></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><strong>CycleEnd</strong></font></div></td>
            <td colspan="2" align="center" valign="middle"> <div align="center">
                <div align="center"><font color="#000000" size="1"></font></div>
                <div align="center"><font size="1"><strong>Book</strong></font></div>
                <font color="#000000" size="1"></font></div>
              <div align="center"></div></td>
          </tr>
<%
    for( int ii=0; snames!=null && ii<snames.length; ii++ )
    {
      String siteName = snames[ii];
      //String siteName = request.getParameter("SiteName");
      //if( siteName == null ) siteName = "";
      int selCyc=Integer.parseInt( request.getParameter("SelectCyc"));
      int year=Integer.parseInt( request.getParameter("SelectYear"));
 
      //cs.setString(1, siteName );
      cs.setString(1,siteName);
      cs.setInt(2, selCyc );
      cs.setInt(3, year);
   
      ResultSet rs = cs.executeQuery();
      while (rs.next())
      {
%>
          <tr bgcolor='#EEEFF3' onMouseOver="this.bgColor='#B2C4F0';" onMouseOut="this.bgColor='#EEEFF3';">
            <input name="siteId" type="hidden" value="<%=rs.getString("SiteID")%>">
            <td height="12"> <div align="center"></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><%=rs.getString("SiteLocation")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString("SiteType")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Prismatic")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Illuminated")%></font></div></td>
            <input name="cycleId" type="hidden" value="<%=rs.getString("CycleID")%>">
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleStart")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleEnd")%></font></div></td>
            <input name="bookYear" type="hidden" value="<%=rs.getString("BookYear")%>">
            <td width="120"><div align="center"><font color="#000000" size="1">
                <input type="checkbox" name="bookingsNo" value="<%=rs.getString("BookingsNo")%>">
                </font></div></td>
          </tr>
<%
        } // end the while loop
    }// end the for loop
%>
        </table>
        <div align="center"> </div></td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"></td>
    </tr>
    <tr valign="middle">
      <td height="21" colspan="4" align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compAddress" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">City </font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="cityName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Country</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="countryName" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Postcode</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="postCode" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Phone Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="phoneNum" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Fax Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="faxNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Email Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="emailAdd" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Category</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodCat" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Price</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="priceNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"><input type=submit name=Submit value="BookIt"></td>
    </tr>
  </table>
</form>
<%
}
    catch (Exception e)
    {
     e.printStackTrace() ;
     out.print("Exception: " + e);
       

    }
    finally
    {
     if( cs != null ) try { cs.close(); } catch( Throwable t ) { t.printStackTrace(); }
     if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
    }
%>
</body>
</html>
0
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!

 
LVL 35

Expert Comment

by:TimYates
ID: 11828581
or, if you want a form (and table) for each loop round the for loop, then move the end for down to after the table :-)

Tim
0
 
LVL 11

Assisted Solution

by:sompol_kiatkamolchai
sompol_kiatkamolchai earned 50 total points
ID: 11828963
I agree with Tim.

0
 

Author Comment

by:Gar04
ID: 11834690
tim, you are the bomb!!!
cheers mate
it works fine
i was in a muddle with the formatting
my system is coming together now and it has been greatly helped
by some of the code you provided cos i have analysed and modified it for other
parts too.

sompol, thanks for you input too!!

:)
Gaz
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11838640
:-)  Good luck with it fella :-)

Glad I could help!

Hope you are ok!

Tim
0

Featured Post

Industry Leaders: 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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 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