tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From phi...@free.fr
Subject Using a context.xml file in <catalina home>/conf/Catalina/local/context.xml
Date Wed, 02 Nov 2016 15:01:46 GMT
Hello,

I've a developed a simple servlet in Eclipse which is supposed to display a welcome message
stored in <apache home>/conf/Catalina/localhost/context.xml.

When I run the web application from Eclipse in a local Tomcat instance, I get the following
message:

"javax.naming.NameNotFoundException: The name welcomeMessage is not bound to this Context"

The only way to prevent the above message from being displayed is to create a context.xml
file in
the project's META-INF directory. However, for my purposes, I need to store the context.xml
file outside of the project's WAR.

Any help with this issue would be much appreciated.

Cheers,

Philippe


---------------------

@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public MyServlet() {
        super();
    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
		
		try {
			Context initCtx = new InitialContext();
			String welcMessage = (String) initCtx.lookup("java:comp/env/welcomeMessage");
			response.getWriter().append(welcMessage);
		} catch (NamingException e) {
			e.printStackTrace();
		}
...

----------------------------------

Here are the contents of the <catalina home>/conf/Catalina/localhost/context.xml file:

-------------------------------------

<Context>
	
	 <Environment name="welcomeMessage" type="java.lang.String" value="Welcome to DEV - localhost!"
/>
	  
	
	
</Context>

------------------------------

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


Mime
View raw message