I am using Jetty to deploy a production website. Let's assume my website is foo.com When I point my browser to a context which does not exist (say foo.com/notavailable), Jetty shows an error page with information of all the contexts which are deployed on it.
It looks something like this:
No context on this server matched or handled this request. Contexts known to this server are:
- /test ---> org.mortbay.jetty.webapp.WebAppContext@6910fe28{/test,/root/webserver/jetty-6.1.4/webapps/test}
I want to prevent Jetty from showing this message because it contains the full path to the context on the server.
Is there a way to do this?
The context path is the prefix of a URL path that is used to select the web application to which an incoming request is routed. Typically a URL in a Java servlet server is of the format http://hostname.com/contextPath/servletPath/pathInfo, where each of the path elements may be zero or more / separated elements.
To disable indexing/listing: If using the DefaultServlet (provided by default on a standard WebApp/WAR), you'll set the dirAllowed init-param to false. Alternatively, you'll edit your configured web descriptor default (usually declared as webdefault. xml) or your web descriptor override-web.
jetty. xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty.
When configuring Jetty XML you can set showContexts to false on the DefaultHandler.
If you are using older Jetty versions replace org.eclipse.jetty on my example with the old org.mortbay.jetty package structure.
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
<Set name="handler">
<!-- the collection of handlers that will handle the request -->
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<!-- primarily handles the request and maps the request to a ContextHandler -->
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<!-- The default handler ... handles the request if not yet handled -->
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
<!-- The handler for your request logs -->
<Item>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- ===================== -->
<!-- DefaultHandler config -->
<!-- ===================== -->
<Ref id="DefaultHandler">
<Set name="showContexts">false</Set>
</Ref>
</Configure>
Maybe you'll also be wanting to prevent directory browsing configuring the DefaultServlet of your web.xml,
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With