0

I'm trying to map a specific URL /the-url to a static resource on the file system {WAR}/static/file.html using web.xml with Jetty 9.4.41.

I thought this would be relatively simple to figure out but I can't find anything relevant in the jetty docs or find any examples of doing this in web.xml. I've been trying to find the possible options for <servlet> in the hope that there's an option that will help to do this.

I know that I can map resources to exact names as in the URLs using the default Jetty servlet e.g.

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/*</url-pattern>
</servlet-mapping>

...but I'm looking to do something like:

<servlet-mapping>
    <servlet-name>MySpecificResource</servlet-name>
    <url-pattern>/the-url</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>MySpecificResource</servlet-name>
    <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
    <!-- Something here so that DefaultServlet knows to serve /static/file.html ?? -->
</servlet>

I know that I can create a Java servlet that will load the file from the filesystem and serve it up, but since I don't need to make any modifications to the file, is there any way to have the XML config handle this for me and save me from cluttering my code base unnecessarily?

RTF
  • 6,214
  • 12
  • 64
  • 132

1 Answers1

0

First, Jetty 9.4.x is now at End of Community Support.

See: https://github.com/eclipse/jetty.project/issues/7958

Next, Your specific version of Jetty, 9.4.41, is subject to several security vulnerabilities.

See: https://www.eclipse.org/jetty/security_reports.php

You are strongly encourage to upgrade (for multiple reasons)

Finally, this has been answered before in stackoverflow ...

And there's a live example in the jetty-cookbook

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136