0
votes

I get some question today.

This below is my servlet-mapping contents of web.xml

<servlet>
    <servlet-name>static-resource</servlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>static-resource</servlet-name>
    <url-pattern>/statis-resource/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

My application directory structure is:

/WEB-INF
/static-resource

I hope to this

  1. This case of the request is mapping to static-resource servlet

    • http://myserver/static-resource/test.js
    • http://myserver/static-resource/images/img1.jpg
    • http://myserver/static-resource/test.xml
  2. And this case of the request is mapping to dispatcher servlet

    • http://myserver/other/whole/uri

But, my web.xml is whole of the request mapping to dispatcher servlet directly. Below is my glassfish server log on request

[#|2014-10-28T09:54:27.722+0900|WARNING|glassfish3.1|org.springframework.web.servlet.PageNotFound|_ThreadID=680;_ThreadName=Thread-1;|No mapping found for HTTP request with URI [/static-resource/test.js] in DispatcherServlet with name 'dispatcher'|#]

So, I wondered, why whole of requests are mapped to dispatcher servlet? Anyone help me?

Update


Sorry my misstake, I correct misstype but still response 404 error. Hmm... probably have another problems?

1
Because you typed statis-resource instead of static-resource? - Robby Cornelissen

1 Answers

1
votes

Servlet mapping is done on the basis of most specific URL matching. So you are using the right approach but just doing a typo mistake for word static in your URL here:

<url-pattern>/statis-resource/*</url-pattern>

change it to

<url-pattern>/static-resource/*</url-pattern>