Tuesday, July 26, 2011

Difference between Jsp:forward and jsp:include

When you do jsp:forward, pageContext.forward() method is invoked with the given jsp or html resource. When you do jsp:include, JspRuntimeLibrary.include() method is getting invoked. jsp:forward means, browser will show only the resource given as an input to jsp:forward. No new HttpServletRequest and HttpServletResponse objects are created hence all parameters/attributes in HttpServletRequest are passed to the new resource as well. jsp:forward does not change the Url in the browser but HttpServletResponse.sendRedirect() changes the url as well since the request is redirected to the browser and coming back to the servlet/action class.