This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
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
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1629
    
  23

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!
 
 
subject: getServletContext().getContent() returning null
 
Similar Threads
passing session values between two web application
j2eeCertificate Ques.
2) getContext - absolute path
j2eecertificate mock exam question
What is allowed after forward() ?