to call a servlet in a jsp and the result will be shown in that jsp again

Hi,i want a program in which a jsp page call a servlet class and after performance and logic the result should be displayed in the same jsp page?thanks in advance
[183 byte] By [kumar@sunila] at [2007-11-27 4:30:22]
# 1

the technique is called "forwarding". You do a submit to the servlet from your first JSP, then after all logic is performed you "forward" to the JSP. To share information between your servlet and JSP, put data in the request object by calling the setAttribute() method. In the JSP you can use this data using EL expressions.

Lets say in the servlet you do this:

request.setAttribute("name", "kumar");

Then after the forward in your JSP you can do this:

name: ${requestScope.name}

the "requestScope" part is not required, but it helps to prevent name clashes with variables stored in the session.

To do the forward from the servlet, get a RequestDispatcher from the request object. Look up the javadoc for getRequestDispatcher() for more information.

gimbal2a at 2007-7-12 9:39:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...