Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem using RequestDispatcher

 
ramu av
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic