This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Servlets don't return anything. Thus, the servlet must put the ArrayList in some scope such as request scope and have the JSP get the variable out of that scope. The functionality of getting the ArrayList could always be implemented in a regular Java object and you could call a method like getList() on that object from your JSP.
Problem is I dont want to use DAO's directly in my JSP page. I want this to happen through the controller TestServlet.
Good practice. But your thinking is a bit backwards -- you are asking a JSP to get info from a servlet rather than the servlet giving info to the JSP. Usually it is the servlet that is invoked, does its processing, and then forwards on to the JSP for processing.
But, from what you are saying, you want the default JSP file, index.jsp, to start this action.
So, what I would do in your case, is to have index.jsp be just a placeholder page that immediately forwards on to your servlet. Check out the <jsp:forward> action to accomplish this.
Your servlet would then gain control, perform its processing (including putting the list on the request as an attribute), and then forward on to a JSP page, perhaps results.jsp that displays the results.
Usually in a Model 2 (MVC) web app, URLs resolve to the servlet controller and not to JSP files. But index.jsp is special case that could be handled as described above.
It's also possible to set up your app such that the 'default' URL is not index.jsp, but rather your servlet, but I've heard that sometimes there are problems doing this in older containers. You may want to investigate this tactic. [ August 13, 2004: Message edited by: Bear Bibeault ]