Lung wrote:

> I have some problems with the getContext method.
>
> According to the servlet specification, the getContext(String path)
> method of class ServletContext
> returns allows servlet gain access to other context. And the
> getRequestDispatcher(String urlPath) returns a RequestDispatcher of the
> given urlPath, which is relative to current context root. But the
> document doesn't not state clear what is the context root. Do anyone
> know what the context root is?
>

The "context root" is the prefix of a request URI to which you've attached your
web application (and the associated servlet context).  For JSWDK and Jakarta
Tomcat, you set this in the "server.xml" configuration file (it is the "path"
attribute of the <Context> element).  In JRun, there is probably a setting for
this in your configuration screens somewhere.

The servlet engine starts at the beginning of your request URI until it recognizes
one of the configured context roots.  It then asks the corresponding servlet
context to figure out which servlet should be executed, based on either matching
the next portion of the request URI, or by matching on the filename extension.

>
> By now I am assuming that the current directory is the context root. So
> given the following path
>
> /member/info.jsp
>
> The following two should return the same requestDispatcher when used in
> JSP:
>
> getServletContext().getRequestDispatcher("/member/info.jsp");
>
> getServletContext().getContext("/member").getRequestDispatcher("/info.jsp");
>
> I tried the above in JRun but the second method returns null.
>

This won't work unless:

* You have created a servlet context with a context root of "/member".

* A file named "info.jsp" is stored in the document root directory
  of this context.

* Your servlet engine has been configured to allow getContext()
  to work -- the servlet spec allows the servlet container to
  disable it for security reasons, to prevent you from accessing
  the internals of a different web application running in the
  same container.

>
> Any help is appreciated.
> Daniel
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to