This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getServletContext().getContent() returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "getServletContext().getContent() returning null" Watch "getServletContext().getContent() returning null" New topic
Author

getServletContext().getContent() returning null

Chandella Montero
Ranch Hand

Joined: Feb 18, 2011
Posts: 89
I have created two web applications to test getting the ServletContext of one application from within another application.

Code for the first Servlet, from the first application:



This will print the path "/MyServlets", which I will use in the second Servlet, as well as "from within the same servlet, flavour is: vanilla", which proves that this value has been set (I set it in the deployment descriptor).

Now here is the code for the second Servlet, which lives in the second application:


What am I doing wrong?

Thanks in advance for your help


OCA, OCP Java 6
Frits Walraven
Rancher

Joined: Apr 07, 2010
Posts: 1042

Hi Chandella,

What am I doing wrong?

If you are using Tomcat as a server you have to put the following line in either the server.xml or better the context.xml of your server:

Regards,
Frits
Chandella Montero
Ranch Hand

Joined: Feb 18, 2011
Posts: 89
Spot on, added that line to context.xml and it now works

Thank you ever so much, Frits!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: getServletContext().getContent() returning null
 
Similar Threads
What is allowed after forward() ?
j2eeCertificate Ques.
j2eecertificate mock exam question
2) getContext - absolute path
passing session values between two web application