Solved

Need Help with formatting JSP

Posted on 2004-08-18
7
322 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
Comment Utility
Is there any error or exception throw out?
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:TimYates
Comment Utility
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
Comment Utility
I agree with Tim.

0
 

Author Comment

by:Gar04
Comment Utility
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
Comment Utility
:-)  Good luck with it fella :-)

Glad I could help!

Hope you are ok!

Tim
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now