• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Servlet to servlet

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
How to call from one servlet to another servlet.
Thanks
Jowsaki
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are calling one servlet from another then you probably needs to reconsider how you've coded you app. It is likely you need to extract the code used into a java bean and then you can use it in both without duplicating code or need to spin off another request reponse cycle (causing a double hit to the server for every user hit to that servlet
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sham
You may want to look at the javax.servlet.RequestDispatcher's forward() and include() methods.
Mark.
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
Thanks for ur reply...
am using dispatch stuff like below.. is it correct?
request.setAttribute("msi",msi);
request.setAttribute("keyword",key);
RequestDispatcher rd=getServletContext().getNamedDispatcher("ScdsServlet");
rd.forward(request,response);
i tried this, it is not forwarding.
Can you pls advise me..
tks
cheers
jowsaki
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sham
When using getNamedDispatcher(String name), the name parameter must be the name of the servlet as defined in the web.xml deployment descriptor, for the same web application.
You can also use getRequestDispatcher(String path), where the path parameter is the path to the required resource. This method exists in both the ServletRequest and ServletContext interfaces. The ServletRequest version may be relative, whereas the ServletContext version must start with a "/".
For example:

Hope this helps
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark

Originally posted by Mark Howard:
Hi Sham
When using getNamedDispatcher(String name), the name parameter must be the name of the servlet as defined in the web.xml deployment descriptor, for the same web application.
You can also use getRequestDispatcher(String path), where the path parameter is the path to the required resource. This method exists in both the ServletRequest and ServletContext interfaces. The ServletRequest version may be relative, whereas the ServletContext version must start with a "/".
For example:

Hope this helps

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
whenever am forwarding request dispatcher.. it is return always null in my ScdsServlet.
request.setAttribute("msi",msi);
request.setAttribute("keyword",key);
RequestDispatcher rd=getServletContext().getNamedDispatcher("ScdsServlet");
rd.forward(request,response);

Can you pls advise me..
tks
cheers
jowsaki
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sham Jowsaki:
whenever am forwarding request dispatcher.. it is return always null in my ScdsServlet.


At what point exactly is a null being returned?
 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark..
I solved the problems.. made mistake while passing parameters.
tks
jowsaki
 
Story like this gets better after being told a few times. Or maybe it's just a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic