1

I'm using Jetty 8.1.4 with Spring 3.2.4. Following is my web.xml file. I have an index.html file under WEB-INF and I want that page to be hit when I do http://myapp.com/ or simple http://myapp.com but I'm getting 404. If I do http://myapp.com/index.html it works. I'm not sure what I'm missing. Also, I'm bit confused if I must use / or /* in the url-pattern below, I tried both.

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="DOMAINAPPROVALGUI" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>myapp-ui</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/myapp-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <session-config> <session-timeout>10</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>myappname</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>myappname</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> 

4 Answers 4

2

Jetty 8 is EOL (End of Life), upgrade to Jetty 9. (The answer here is provided based on how Jetty 9 operates.)

The <welcome-file-list> is part of the DefaultServlet handling (per servlet spec).

Your declaration of myappname at <url-pattern>/*</url-pattern> is effectively preventing the DefaultServlet from doing anything.

Your configuration has basically said "send all requests to my DispatcherServlet".

This even includes static file serving, welcome-file handling, default handling, error handling, dispatching, and much much more.

As for what url pattern to choose, that's up to you.

There are many ways to use Spring, your current configuration at /* is just as valid as others that have it at *.do or *.dispatch or /dispatch/*

You have to decide what is best for your webapp, and adjust your internal use of Spring to satisfy your needs (such as how you declare your RequestMapping's)

Now that you know why <welcome-file-list> isn't working, you can make adjustments to either not use the standard servlet <welcome-file-list> (using something internally in Spring), or adjust your dispatcher servlet url pattern to allow the servlet container (Jetty) to serve your static files and handle your declared <welcome-file-list>.

Sign up to request clarification or add additional context in comments.

3 Comments

BTW, static file handling works fine. Like, if do domain.com/index.html I can see it from browser. Dispatcher doesn't know about my index.html.
Yes, your dispatcher knows about it, it was the one that gave you that index.html (the servlet container didn't do it)
Go ahead and request a static resources you don't have, like /foodex.html and you'll likely see a log along the lines of WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/foodex.html] in DispatcherServlet with name 'myappname'
0

I added below to my servlet.xml to make this work. Agree with @Joakim Erdfelt answer that request went to spring. But not sure how directly entering index.html in url worked.

<mvc:view-controller path=”/” view-name=”index” /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".html" /> </bean> 

Comments

0

Firstly, Your servlet mapping config of spring is not right , it will mapping all thing and link to spring , this means that *.jsp would be handled by spring. So You Should fix this flaw config. But after doing this, it still would not be right to access the welcome page. this is a character of Jetty.

I Must Say: there is some difference between tomcat and jetty. Tomcat can handle this with right behaviour but jetty not.

You can try to verify by below step.

  1. delete the mapping with "/"
  2. and run the app with tomcat and jetty. you can find out tomcat and jetty both works.
  3. if you add a servlet mapping with mapping pattern : "/" ,either with a customer servlet or spring dispatch servlet. it will work right in tomcat but jetty not.

Comments

-1

i think placing you welcome file at the start will help you to load the file.To be precise place it after the display tag

1 Comment

This should not make any difference.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.