0

Error:

 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/WEB-INF/jsp/summary/homePage.jsp] in DispatcherServlet with name 'spring'

web.xml

  <servlet-mapping>
     <servlet-name>spring</servlet-name>
     <url-pattern>/*</url-pattern>
  </servlet-mapping>

My page exists in that directory and if the url pattern is setup like <url-pattern>/ANYSTRING/*</url-pattern> my pages work just fine. To elaborate: My controller uses @RequestMapping(value = "/home"). When the url pattern is /potato/* and I navigate to localhost:8080/potato/home my page works perfectly. But if I keep the same settings with the url pattern being /* it gives me the 404.

Tried:

  1. Using a jsp servlet mapping to my pages directory, but it causes other mapping problems.
  2. adding <mvc:default-servlet-handler/> to spring-servlet, but this displays the source of my page.
  3. Change url pattern to <url-pattern>/</url-pattern> but it causes other mapping problems.

Could anyone shed some light on my problem? I am editing as I try different possible solutions.

Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78

2 Answers2

1

Try with <url-pattern>*.jsp</url-pattern> pattern.

You can define multiple url-pattern for the same servlet.

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/abc/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/abc/xyz/*</url-pattern>
</servlet-mapping>

It might help you to understand the url-pattern

Servlet Matching Procedure

A request may match more than one servlet-mapping in a given context. The servlet container uses a straightforward matching procedure to determine the best match.

The matching procedure has four simple rules.

  • First, the container prefers an exact path match over a wildcard path match.

  • Second, the container prefers to match the longest pattern.

  • Third, the container prefers path matches over filetype matches.

  • Finally, the pattern <url-pattern>/</url-pattern> always matches any request that no other pattern matches.


Have a look at my post How does a servlets filter identify next destination is another filter or a servlet/jsp? for detailed description.

Problem Solved:

Add this mapping to handle the jsp pages directly (web.xml):

  <servlet-mapping>
     <servlet-name>jsp</servlet-name>
     <url-pattern>/WEB-INF/jsp/*</url-pattern>
 </servlet-mapping>

Add this to make the rest of the resources in the project accessible (spring-servlet.xml):

<mvc:resources mapping="/assets/**" location="/assets/"/>

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76
  • I get the 404 on the page without the console giving me a mapping problem with `*.jsp` - i am looking into the rest of your answer now. – Jordan.J.D May 23 '14 at 14:17
  • What is the URL formed? – Braj May 23 '14 at 14:18
  • Please read [Spring 3 RequestMapping: Get path value](http://stackoverflow.com/questions/3686808/spring-3-requestmapping-get-path-value) – Braj May 23 '14 at 14:22
  • I add ` jsp /WEB-INF/jsp/* ` and the page shows but I get problems with other mappings like bootstrap? - I am still trying to read through everything you gave me. Thanks for your time. – Jordan.J.D May 23 '14 at 14:34
  • 1
    I added the above to handle the pages then I added `` to handle the rest of the resources. If you find a way to include this in an edit I will accept your answer. – Jordan.J.D May 23 '14 at 14:46
  • Finally you got the solution. I just give you an idea. You are genius. :) My master says :- A hint is enough for an intelligent guy. – Braj May 23 '14 at 14:47
  • accept my edit and i will accept your answer since that is how i solved it – Jordan.J.D May 23 '14 at 14:52
0

And your controller RequestMapping?

"/*" makes your servlet intercept all kinds of requestmapping, so if there's not a correspondent methode it won't find the right methode and gives "no mapping".

This is because your files in WEB-INF are not publicly accessible.

I suggest you to use some suffix in the url-pattern , something like ".do" .

ROROROOROROR
  • 959
  • 1
  • 14
  • 31
  • My mappings and controllers work fine if the url pattern is `/potato/*`, why would `/*` give me a problem? – Jordan.J.D May 23 '14 at 13:36
  • can you post your controller? do you have this in the controller? >@Controller @RequestMapping(value = "potato") – ROROROOROROR May 23 '14 at 13:38
  • No, that is not what I was referring to. The url pattern is in `web.xml` and my controller uses `@RequestMapping(value = "/home")`. When the url pattern is `/potato/*` and I navigate to `localhost:8080/potato/home` my page works perfectly. - added this to my question for others in case it is confusing. – Jordan.J.D May 23 '14 at 13:42
  • well, weird, what I've understood is. by setting url-pattern "/" or "/*", the servlet will capture all of the request. In this case, if you try localhost:8080/potato/whatever, it won't find the right mapping, but if you use a correct mapping which exists in your controller, it will somehow redirect the page according to your viewResolver setting. better don't use "/" or "/*" I think. – ROROROOROROR May 23 '14 at 14:13
  • well. if you are using .jsp suffix as url pattern, don't forget to modify the mapping. home -> home.jsp – ROROROOROROR May 23 '14 at 14:23