Adam Sturge
Adam Sturge

Reputation: 57

hosting a file on jetty

I'm a jetty newbie. I know how to specify servlet names and mappings in the web.xml file by using the <servlet> and <servelet-mapping> tags, but how do I host general files on my jetty server so I can call on them? Specifically I want to upload some images and an html file. I am using a war file.

Upvotes: 0

Views: 2578

Answers (2)

Tim
Tim

Reputation: 6519

If you're creating a war file, then you don't need to do anything special in Jett (or any other servlet container)

Simply put your HTML and Image files inside the war file. As long as they are someone other than in the WEB-INF directory, then they'll be available to clients.

Assuming you're using standard Jetty deployment mechanisms, then if you have a war file called myapp.war and it has the following contents:

myapp.war:
    pages/
        index.html
    images/
        logo.png
    WEB-INF/
        classes/
            com/
                example/
                    MyServlet.class
        lib/
            support.jar

then your index.html page would be available at http://localhost/myapp/pages/index.html (typically with a port number in there, for whatever port you're running Jetty on)

Upvotes: 2

Devin M
Devin M

Reputation: 9752

You would want to use the DefaultServlet to serve images and other static content. The documentation is here and an example config would look like this:

  <servlet>
    <servlet-name>staticAssets</servlet-name>
    <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>staticAssets</servlet-name>
    <url-pattern>/static/*</url-pattern>
  </servlet-mapping>

In your WAR file anything placed inside the static directory will be served under the appropriate URL.

Upvotes: 2

Related Questions