Click to See Complete Forum and Search --> : JSP Declaration Tags? And Some Help On Simple Paging..


inflexjunkie
06-15-2006, 05:49 AM
hi peeps.. pretty new to JSP.. im having a problem using declaration and directive tags.. im not too sure about implementing the function in <%! %>

when i run the bottom code.. it gives me error on the declared method getContent()..

also.. would appreciate any help on a simple paging method for the bottom code.. i wanna know how do i actually code functions into the buttons rendered only at server-side? thanks in advance guys! :)


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>

<%@ page import = "java.io.*, java.net.*, java.sql.*, OnlineShop.DBConnection.*" %>

<%!
public void init(){
DBConnection.loadDriver();
}

public String getContent() {
Connection objConn;
Statement objStmt;
ResultSet objRS;

objConn = DBConnection.getConnection();
objStmt = DBConnection.getStatement(objConn);

String strContent;

int intNumOfRows = 0; //COUNTER FOR NUM OF ROWS

try {

String strSQL = "SELECT * FROM tblMobilePhone ORDER BY strBrandName, dblPrice";

objStmt = objConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
objRS = objStmt.executeQuery(strSQL);

objRS.last();
intNumOfRows = objRS.getRow(); //TOTAL NUM OF ROWS
objRS.beforeFirst();

int intNumOfPages = intNumOfRows / 2; //TOTAL NUM OF PAGES

String strBrandName;
String strModelName;
String strFunction;
double dblPrice;

if (objRS.next()) { //RECORDS FOUND

strContent = "<table align='CENTER' bordercolor='BLACK' width='100%'>" +
"<tr>" +
"<td width='15%'><h5>BRAND</td>" +
"<td width='10%'><h5>MODEL</td>" +
"<td width='15%'><h5>MODEL IMAGE</td>" +
"<td width='30%'><h5>FUNCTION</td>" +
"<td width='15%'><h5>PRICE ($)</td>" +
"<td width='15%'><h5>PURCHASE</td>" +
"</tr>" +
"<tr><td>"; //CREATE TABLE

int intCounter = 0;

do { //RETRIEVE AND DISPLAY DATA IN TABLE
strBrandName = objRS.getString("strBrandName");
strModelName = objRS.getString("strModelName");
strFunction = objRS.getString("strFunction");
dblPrice = objRS.getDouble("dblPrice");

strContent += strBrandName + "</td><td>" +
strModelName + "</td><td>" +
"<img src='images/" + strModelName + ".gif' /></td><td>" +
strFunction + "</td><td>$" +
dblPrice + "</td><td>" +
"<a href='/AddToCart.html'><img src='images/btnAddToCart.gif' /></a></td>";
strContent += "<tr><td>";

intCounter++;

} while (objRS.next() && intCounter < 2);

//START PAGING
strContent += "<tr><td align='RIGHT' colspan='6'>" +
"<input type='submit' name='btnPrevious' value='Previous' />";

strContent += "<input type='text' name='txtPaging' readonly='true' size='10' " +
"value=' Page 1 of " + intNumOfPages + "'" + " />";

strContent += "<input type='submit' name='btnNext' value='Next' />" +
"</td></tr>";
//END PAGING

} else { //IF NO RECORDS FOUND
strContent += ""; //PRINT NTH
}
} catch (SQLException e){
System.err.println("ERROR EXECUTING STATEMENT : " + e);
} finally {
DBConnection.closeConnection(objConn);
}

strContent += "</td></tr></table>"; //END TABLE
return strContent;
}
%>

<table id="tblAdvertisement" width="100%">
<tr><td>
<span id="lblAdvertisement"><%= getContent %></span>
</td></tr>
</table>



</body>
</html>