aspose file tools*
The moose likes Servlets and the fly likes Request Dispatcher include? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatcher include?" Watch "Request Dispatcher include?" New topic
Author

Request Dispatcher include?

Rajesh Vijaya
Ranch Hand

Joined: Oct 18, 2005
Posts: 48
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 ]

Rajesh <br /> <br />SCJP1.4 SCWCD1.4 SCBCD 1.3 ,SCDJWS(Preparing..)<br /> <br />There is no free will.It is the phenomenon bound by cause and effect.But there is something behind will which is free---Swami Vivekananda...
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Check out ServletContext.getNamedDispatcher(). You shoudl also see the API description of the method.

Dave
Rajesh Vijaya
Ranch Hand

Joined: Oct 18, 2005
Posts: 48
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
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
I believe you have to define and give the jsp a name in web.xml


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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

Joined: Jan 28, 2004
Posts: 569
BTW, why don't you use getServletContext().getRequestDispatcher() instead? In this way, you just provide a path - instead of servlet name - to the method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request Dispatcher include?
 
Similar Threads
problem in excuting Basicservlet
Tomcat version
HTTP method GET is not supported by this URL
Counter using Session Tracking !!
File upload - Error 404 - servlet not available