• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 1514
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic