You need to separate the presentation from business logic.. Here is a simple how
You need a servlet (say DisplayController.java)
You need a JSP (MyView.jsp)
Then..through your web browser.. you should call the servlet (assuming you have configured the servlet in web.xml)
In the servlet, you will retrieve the contents from database and put the contents in a list or map or any data structure of your choice. Then you need to get that variable ready to be accessible by UI. That means you should send the variable by adding it at as an attribute to the request.