Am currently working in a module in which am calling a servlet from my jsp ,based on some condition the servlet calls a java class.The java class after performing some operations returns a HashMap ,which i need to display in the main jsp from which i called the servlet. But what happens is jsp is getting executed and displays 0 [If there were no objects found]. But actually speking my class returns the hashmap.
This is a very ambiguous statement and its meaning is not clear. What do you mean by "calling" a servlet?
Calling the doPost or doGet method directly?
Submitting a form to the servlet?
Invoking a URL referencing the servlet?
Including the servlet output in the JSP via the <jsp:include> action?
There really is no "calling a servlet from a JSP" (unless you are calling the doPost() or other servlets method directly, whch would be an egregious thing to do). [ April 15, 2005: Message edited by: Bear Bibeault ]
You question does seem strange... It sounds as if you are trying to remove the business logic from your jsp page (which is a very good thing to do), but you are doing it backwards. Usually the servlet is invoked first, and then forwards the request to a jsp. Here is an example of putting your busines logic in a servlet... When a user clicks on the "Test.do" link...
1) The container looks at the address in the request, and based on that, finds the appropriate servlet in the DD 2) This servlet can call outside java classes, do business logic, and prepare that lovely HashMap you wish to use.
3) The servlet then assigns the HashMap to an attribute (probably in request scope). 4)The servlet uses a RequestDispatcher to forward the request to the jsp.
5) Now the jsp can access the HashMap via the attribute.
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook