aspose file tools*
The moose likes Servlets and the fly likes getContext() always returns null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getContext() always returns null" Watch "getContext() always returns null" New topic
Author

getContext() always returns null

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Hi all, i am having some problems in context paths and im hoping somebody here might be able to help me.

I've got two files, a jsp page and a java file in the background.

The jsp file calls a method in the java file as shown below



The java file the calls another method as shown below. servlet in the parameters is the "application" value passed from the jsp page.


Within checkLogin, i try to get the context for an application as shown below. "context" below is the result of servlet.getServletContext() in teh call.



For some reason crmsAuthContext is always null and im not sure why. The way the application is structured in Tomcat is that it is deployed in multiple war files as shown below.



The above code is from the /core application and i am trying to call something from the /admin application. Whenever i try to get the context of /admin it return null. Can anyone help?

Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hai,

you already pass servletContext into java class

using
UserAuth userauth = Login.checkLogin(application, request, response, null);

then once again why you want to access...you can use the application right?...

correct me ,if i am wrong
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You have to make sure both the "/core" and the "/admin" contexts are set to crossContext="true", which you do in their respective <Context> elemens.


Steve
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

Originally posted by seetharaman venkatasamy:
Hai,

you already pass servletContext into java class

using
UserAuth userauth = Login.checkLogin(application, request, response, null);

then once again why you want to access...you can use the application right?...

correct me ,if i am wrong



Hi,

It is passed from a jsp page as "application" to a servlet. the servlet that recieves it uses it by passing it to another method using servlet.getServletContext(). The method that recieves it uses it to access the actual context using context.getContext("/admin")

Thanks
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

i tried the crossContext="true" but it didnt work. Here is what i did,



I added the above code into a file called called admin.xml and placed the file in $CATALINA_HOME/conf/Catalina/localhost/admin.xml

I also tried to put the code into a file called context.xml and placed it in $CATALINA_HOME/webapps/admin/META-INF

I also tried to add the above code in $CATALINA_HOME/conf/server.xml

None of the above options worked.

Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You have to do it for both the /admin context and the /core context (or whichever context you are using that accesses the /admin context).

If you have done so and still doesn't work:
1) Restart the server
2) Launch the server directly. Don't use an IDE to do so.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getContext() always returns null