Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getContext() always returns null

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic