Correct. The code above would be in a service(), doGet(), or doPost() method. The "out" represents the response.getWriter() just as Bosum said.
You could take the above code and move it to a separate class and have it return a
String or StringBuffer instead of writing to out. I will leave that as an excercise for anyone interested.
i.e. create a method with a signature of:
public static StringBuffer buildResultGrid(ResultSet rs)