Servlets are protocol- and platform-independent server side
components that can be dynamically loaded like applets
or can be considered as server side counterpart to applets
or Java application components which are loaded, on demand
Servlets differ from applets in that they are faceless
( without
any graphics ) can be invoked in many ways one of which
of the form
public void
service(ServletRequest req, ServletResponseres)
throws ServletException, IOException{
PrintStream out = newPrintStream(res.getOutputStream());
out.println("Hello world!");
}
public String
getServletInfo() {
return "Hello World Servlet";
}
}
//create and execute the query statement
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
dispResultSet(rs,out);
//close connections here
} Catch(SQLException ex) { //print the exceptions caught }
}
private void
dispResultSet(ResultSet rs, PrintStream out) throws SQLException {
//get the resultset metadata from the result set
ResultSetMetaData rsmd = rs.getMetaData();
//get the # of columns in the table and display the results
while (rs.next() ) {
for (int I;I <= numcols; I++) {
//display the values for each column
}
}
}
}