PDA

View Full Version : table tags in a JSP assignment



tispe
04-28-2008, 11:22 AM
I have this assignment thats pretty much done, but im missing one thing...the output needs to go into tables

http://web.njit.edu/~cp76/IT202/Assignment10/assignment10.html

so right there when you select some options, it runs this code:


<%@ page import="java.sql.*" %>
<%
Connection conn=null;
try
{ Class.forName ("org.gjt.mm.mysql.Driver").newInstance();
conn
= DriverManager.getConnection
("jdbc:mysql://sql2.njit.edu/cp76_proj", "cp76_proj", "ouFmfJKl");
}
catch (Exception exc)
{ out.println(exc.toString() + "<br>"); }
out.println ("Database Connected.");
Statement stm = conn.createStatement();


String s = request.getParameter("D");
out.println ("<br>Select SQL: " + s + "<br><br>") ;


ResultSet x = stm.executeQuery (s) ;

String n;
String a;

while ( x.next ( ) )
{
n = x.getString( "name" ) ;
a = x.getString( "age" ) ;
out.println ( "Name: " + n ) ;
out.println ( "<br>Age: " + a ) ;

out.println ("<br><img src=" + n + " height=300 width=300 /><br><br>");
}

%>


The images though should be put into a table though i guess. I think name and age in one cell and the image in another cell. my guess as to where to start the table tag is right outside the while loop at the end and then put the <td> on the printlines?

tispe
04-28-2008, 01:16 PM
ok i have all the code and assignment information in front of me

the outputted data needs to land in a table. I think the table needs to be arranged somewhere in this code:


while ( x.next ( ) )
{
n = x.getString( "name" ) ;
a = x.getString( "age" ) ;
out.println ( "Name: " + n ) ;
out.println ( "<br>Age: " + a ) ;

out.println ("<br><img src=" + n + " height=300 width=300 /><br><br>");
}


im just not sure where. I couldn't start the table tag outside of the println's since thats in jsp idk i need help on this

tispe
04-28-2008, 05:20 PM
this is due by like tomorrow night guys cmon idk where to put the table in thats the only thing im missing

pulaskeet
04-28-2008, 05:28 PM
The images though should be put into a table though i guess. I think name and age in one cell and the image in another cell. my guess as to where to start the table tag is right outside the while loop at the end and then put the <td> on the printlines?

correct.. before the while loop start a table. then, inside the for loop, put something like


<tr>
<td>item 1</td>
<td>item 2</td>
<td>....</td>
</tr>

then outside of the for loop, put </table>. pm me if you need more help or something, i'll send an im to you

tispe
04-28-2008, 05:32 PM
i got it pulaskeet



out.println("<table border = 1>");
while ( x.next ( ) )
{
n = x.getString( "name" ) ;
a = x.getString( "age" ) ;

out.println("<tr>");
out.println ("<td>" + "Name: " + n ) ;
out.println ("<br>Age: " + a + "</td>") ;

out.println ("<td>"+"<br><img src=" + n + " height=300 width=300 /><br><br>"+"</td>");
out.println("</tr>");
}
out.println("</table>");

Vershun
04-28-2008, 09:20 PM
Are you guys going to learn taglibs? Using raw Java in JSPs is archaic :x.

tispe
04-29-2008, 12:32 PM
idk...this is how we did it in class

i know its probably not how people do it irl but its for this fucking class so im not gonna go out o my way to learn it another way. while googling i saw alot of people using java libraries or something but we never learned that in class