Solved

Need Help with formatting JSP

Posted on 2004-08-18
7
325 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion 10 - JSP File Not Found - 404 Error 5 93
I need to add fonts to my PC 6 78
Font install problem 9 46
maven set up 2 144
Data breaches are on the rise, and companies are preparing by boosting their cybersecurity budgets. According to the Cybersecurity Market Report (http://www.cybersecurityventures.com/cybersecurity-market-report), worldwide spending on cybersecurity …
February 24, 2017 — On February 23, Travis Ormandy, a vulnerability researcher at Google, reported on Twitter (https://twitter.com/taviso/status/834900838837411840) that massive stores of data have been leaked by CloudFlare, a company that provide…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

831 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