File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes ways to include a servlet from a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ways to include a servlet from a JSP" Watch "ways to include a servlet from a JSP" New topic
Author

ways to include a servlet from a JSP

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 556
I know how to call a servlet froma JSP using a form. But what I want to do is call a servlet to do some processing from a servlet. I think there is a way round it using ServletDispatcher().include which will call the servlet carry out the process and then return to the calling page.

Problem is I cant find any example code.

Thanks for any help Tony
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
Example in Sun's tutorial. found by Google search for "servlet tutorial requestdispatcher"
Bill
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
RequestDispatcher rd = myServletContext.getRequestDispatcher("/contextRelativePath");
rd.include(request, response);

You can also use a relative path if you get the RequestDispatcher from the ServletRequest object.


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 556
Thanks Tony
Vasilis Karas
Greenhorn

Joined: Mar 16, 2004
Posts: 24
you can use also use a JSP standard Action:

<jsp:include page="/servletUrlMapping" flush="true">
<jsp aram name="paramName" value="paramValue" />
</jsp:include>
 
Consider Paul's rocket mass heater.
 
subject: ways to include a servlet from a JSP
 
Similar Threads
Displaying HTML report on the same page usng JasperReports
Difference between requestDispatcher.forward() and RequestDispatcher.include()?
To call a servlet from a JSP
How can I dispatch Requests to >1 JSP?
Unable to compile class for JSP