This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problem using RequestDispatcher

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic