*
The moose likes Servlets and the fly likes problem using RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem using RequestDispatcher " Watch "problem using RequestDispatcher " New topic
Author

problem using RequestDispatcher

ramu av
Greenhorn

Joined: Feb 25, 2003
Posts: 28
hello all,

i'm trying to include a servlet in another servlet using

req.getRequestDispatcher("LeftNavigate").include(req,res);

but on the first access of the calling servlet the "Leftnavigate" servlet is not called.

but on referesh of the calling servlet it includes "LeftNavigate"

please give me some suggestions to handle this problem.
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Could this be because the servlet "LeftNavigate" has not yet loaded when you call the calling servlet.
Try pre-loading the servlets by specifying <load-on-startup> in the web.xml.

Specify a lower value for your "LeftNavigate" servlet so that it is loaded first when the webapp starts.

<servlet>
<servlet-name>LeftNavigate</servlet-name>
...
<load-on-startup>1</load-on-startup>
...
</servlet>
<servlet>
<servlet-name>CallingServlet(whatever is its name)</servlet-name>
...
<load-on-startup>2</load-on-startup>
...
</servlet>

Not sure if this is the cause, just give it a try.
Sheldon Fernandes
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi Ramu,
I think you can try to use method getNamedDispatcher(String name) in ServletContext.
Because that method returns a RequestDispatcher object that acts as a wrapper for the named servlet.

Correct me if I am wrong..
Hope this help

thanks
daniel
Haitham Ismail
Greenhorn

Joined: Nov 22, 2004
Posts: 4
Originally posted by ramu av:
hello all,

i'm trying to include a servlet in another servlet using

req.getRequestDispatcher("LeftNavigate").include(req,res);

but on the first access of the calling servlet the "Leftnavigate" servlet is not called.

but on referesh of the calling servlet it includes "LeftNavigate"

please give me some suggestions to handle this problem.


---------------------------------------------
Dear Ramu,
the signature of getRequestDispatcher method is:
request.getRequestDispatcher(String relativePath);
where the relativePath is a path relative to the current page.

so, to solve this problem add the following part to your web.xml file:
<web-app>
...
<servlet>
<servlet-name>Included</servlet-name>
<servlet-class>com.Included</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Included</servlet-name>
<url-pattern>/LeftNavigate</url-pattern>
</servlet-mapping>
...
</web-app>


SCJA 1.0 SCJP 1.4 SCWCD 1.4 SCBCD 1.3
 
Don't get me started about those stupid light bulbs.
 
subject: problem using RequestDispatcher