Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Servlet to servlet

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks Mark..
I solved the problems.. made mistake while passing parameters.
tks
jowsaki
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic