Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get return value from servlet inside JSP page...

 
Eric Choley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like display in a JSP page the result of a servlet (with argments : something like this /servlet/myServlet?id=5).
I try to use the dispatcher.include() but something goes wrong...
Someone has some sample code to use this dispatcher ? or any ideas to get result from servlet ?
Thanks,
Eric
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric
Can you give us more of a description of what goes wrong? Do you get any exceptions or strange ouput?
 
Eric Choley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,
I m starting with JSP and i have some difficulties to understand this dispatcher and the setAttribute method... i try this code :
<pre>
<%
String servletUri="/servlet/myServlet";
request.setAttribute(servletUri,"action=admin");
// Get the dispatcher from the page context
RequestDispatcher dispatcher = pageContext.getServletContext().getRequestDispatcher(servletUri) ;
if ( dispatcher == null ) {
throw new Exception ( "Unable to find " + servletUri );
}
dispatcher.include (request, response);

HttpSession session_ = pageContext.getSession();

String returnedValue = (String) session_.getAttribute (servletUri);
out.println(returnedValue);
%>
</pre>
Do you have any ideas ? Is there a better way to include result from a servlet with parameters ?
Thanks
Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic