Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Request Dispatcher include?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I want to call one servlet from another .I'm writing a simple web-application to accomplish the same.

My context root is Test.

I have the following files

Test/test.html

<html>
<body>

<form action=SS method=post>

<input type=submit value=go>

</form>

</body>

</html>

Test/WEB-INF/classes/Test

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class Test extends HttpServlet {

public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {

PrintWriter out = resp.getWriter();

out.println("I' m inside calling servlet");

// What should i specifiy in the path ???

getServletContext().getNamedDispatcher("Test2").include(req,resp);

}

}


Test/WEB-INF/classes/Test2


import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

public class Test2 extends HttpServlet {

public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {

PrintWriter out = resp.getWriter();

out.println(" I'm inside called servlet");



}

}


Thanks

Rajesh
[ February 11, 2006: Message edited by: Bear Bibeault ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out ServletContext.getNamedDispatcher(). You shoudl also see the API description of the method.

Dave
 
Rajesh Vijaya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David ,

I did check them and i did check the Spec too...could you please tell me what to specify in the Path .....i'm unable to fix it ....


Thanks

Rajesh
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you have to define and give the jsp a name in web.xml
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API spec is not very explicit on this. But, I believe it is refering to the <servlet-name> element under <servlet>.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, why don't you use getServletContext().getRequestDispatcher() instead? In this way, you just provide a path - instead of servlet name - to the method.
 
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic