Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ways to include a servlet from a JSP

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example in Sun's tutorial. found by Google search for "servlet tutorial requestdispatcher"
Bill
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tony
 
Vasilis Karas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use also use a JSP standard Action:

<jsp:include page="/servletUrlMapping" flush="true">
<jsp aram name="paramName" value="paramValue" />
</jsp:include>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic