Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets and ServletContext

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am building some servlets and ran into a problem. The problem concerns ServletContext objects and
the getContext method.
The idea is pretty simple and I've seen numerous examples on the topic. I have a servlet that is http://localhost/NASApp/Main/MainServlet.
I have a second servlet that is /localhost/NASApp/Other/OtherServlet. I would like the
MainServlet to forward to the OtherServlet. To do this, I am attempting the following in MainServlet:
RequestDispatcher dispatcher;
ServletContext sc = getServletContext();
sc.getContext("/localhost/NASApp/Other");
dispatcher = sc.getRequestDispatcher("/OtherServlet");
dispatcher.forward(request, response);
This appears to agree with documentation and examples that I have found, but I get a 404 error. I have
tried "/Other", "/NASApp/Other", and "/localhost/NASApp/Other" in the getContext call. The OtherServlet
works fine when you access it directly via typing the URL into the browser, so I know it works. I am
using iPlanet App Server 6.0 and iPlanet WebServer 4.1sp5. I see that the webserver specifies some
things that need to be done to get servlets to work, but I'm not using the webserver for the servlets.
Rather, I am using iAS to deploy my .ear files for me. I haven't found anything in the iAS docs that
point to extra steps that need to be done. Anybody have experience in this area? Your help is greatly
appreciated.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ServletContext sc = getServletContext();
I am not sure, but I always see ppl use this when they want to do sth for entire application and access different application level attributes.
public void contextInitialized(ServletContextEvent sce)
{
ServletContext context = sce.getServletContext();
blas blash
}
and configure ur web.xml file, too
 
mike markey
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I figured it out. I misunderstood the way the sc.getContext("/localhost/NASApp/Other") call worked. I simply needed to assign this call to a new ServletContext such as:
ServletContext newSC = sc.getContext("blahblah");
dispatcher = newSC.getRequestDispatcher("/OtherServlet");
This fixed the problem. Thanks for the reply, though, as it has shown me how to do some other things that I wanted to do.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic