Solved

Servlets and ServletContext in iPlanet App Server

Posted on 2001-06-14
2
241 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:bankerboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
tonus earned 200 total points
ID: 6193910
Hi,
   You can use sendRedirect(String strLocation) method of HttpServletResponse class to forward the request to other servlets

0
 

Author Comment

by:bankerboy
ID: 6202617
Thanks for the reply.  The sendRedirect does indeed work, but it is less efficient since it sends a request to the client's browser which then does the redirect.  The "forward" method is all server side and transparent to the user.  In reality, I just figured out how to use the forward this morning.  All I needed to do was assign the sc.getContext call to a new ServletContext:

ServletContext newSC = sc.getContext("blahblahblah");
dispatch = newSC.getRequestDispatcher("nextPage");

I was forgetting to assign the getContext call to a new ServletContext.  But again, thanks for the reply, since it was a solution that did work.  

0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android development question 2 81
JavaFX TableView not displaying correctly 3 109
Fast way to search item into Java Array (Rhino compatible) 2 39
What browser will run Java? 7 128
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question