You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Peter Chen <pe...@aicent.com> on 2009/12/22 10:13:52 UTC

question about Tomcat5.5 getServletContext().getContext(String url);

Hi,

In a JSP file, there is a sentence like this:

ServletContext sc = this.getServletContext().getContext("/File");

if(sc == null){

  Logger.warn(msg,"Can't get the context of /File.");

  return;

}

 

What's the mean of this sentence?

Now, I run this application in Tomcat5.5, and find the log: Can't get
the context of /File.

How to solve this problem? Thanks.


Re: question about Tomcat5.5 getServletContext().getContext(String url);

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

André,

On 12/22/2009 4:35 AM, André Warnier wrote:
> In other words, [that code] is trying to get the context of a webapp which should
> be located at webapps/File.
> If you do not have such a webapp, then that is the reason for the
> message above.

Tomcat requires a webapp to be configured as "cross-context" enabled in
order to grab the ServletContext from another webapp. If this webapp
isn't cross-context-enabled, then you'll get 'null' whether that webapp
exists or not.

See http://tomcat.apache.org/tomcat-6.0-doc/config/context.html for more
information. Specifically, search for "crossContext" within that page.

> Why it is doing that however, and whether it is a problem, is something
> you will need to ask from the author of the application.

+1

It's not often that you need to grab another webapp's ServletContext,
unless you want to to a server-side forward across webapps. Unless you
have a particular requirement to do this, I would recommend that the OP
de-couple the two (or more?) webapps by using a client-side redirect
instead of a server-side forward.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAksyQjoACgkQ9CaO5/Lv0PAy8QCgp2P7ADzN7WDVwOiAh6S5WqIW
WcoAn36OobTlKOxp/9cP2hZH6nuRzGBz
=e7W0
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: question about Tomcat5.5 getServletContext().getContext(String url);

Posted by André Warnier <aw...@ice-sa.com>.
Peter Chen wrote:
> Hi,
> 
> In a JSP file, there is a sentence like this:
> 
> ServletContext sc = this.getServletContext().getContext("/File");
> 
> if(sc == null){
> 
>   Logger.warn(msg,"Can't get the context of /File.");
> 
>   return;
> 
> }
> 
>  
> 
> What's the mean of this sentence?
> 
> Now, I run this application in Tomcat5.5, and find the log: Can't get
> the context of /File.
> 
> How to solve this problem? Thanks.
> 
> 
Have a look here (obtained via Google) :
http://java.sun.com/products/servlet/2.3/javadoc/javax/servlet/ServletContext.html#getContext%28java.lang.String%29

In other words, it is trying to get the context of a webapp which should 
be located at webapps/File.
If you do not have such a webapp, then that is the reason for the 
message above.
Why it is doing that however, and whether it is a problem, is something 
you will need to ask from the author of the application.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: question about Tomcat5.5 getServletContext().getContext(String url);

Posted by Pid <pi...@pidster.com>.
On 22/12/2009 09:13, Peter Chen wrote:
> Hi,
>
> In a JSP file, there is a sentence like this:
>
> ServletContext sc = this.getServletContext().getContext("/File");
>
> if(sc == null){
>    Logger.warn(msg,"Can't get the context of /File.");
>    return;
> }
>
>
>
> What's the mean of this sentence?

Ask the author of the JSP.  Presumably they'd know what it was for.


p

> Now, I run this application in Tomcat5.5, and find the log: Can't get
> the context of /File.
>
> How to solve this problem? Thanks.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org