Tiles 2 And No mapping found for HTTP request with URI - Spring-MVC

大兔子大兔子 提交于 2019-12-28 04:27:31

问题


I want to use Spring-Tiles intergration. Here you can see how my app looks like.

So my question is: why Spring-MVC dispatcher Servlet can not resolve my Target page ???


回答1:


The problem is that you use <url-pattern>/*</url-pattern> in servlet mapping, so all requests are processed by DispatcherServlet, including request to *.jsp tiles. The most versatile way to solve it (but to keep restful urls without prefixes) is to use a UrlRewriteFilter.




回答2:


I think you're missing a critical ViewResolver. I checked the post you mentioned in SpringSource but I didn't see the following ViewResolver:

org.springframework.web.servlet.view.tiles2.TilesViewResolver

Try adding that ViewResolver and see if that would help. I use Spring and Tiles as well. I just have to declare that and the TilesConfigurer.

Check out these references:

  • Add TilesViewResolver to enable fallback if tiles definition does not exist

  • TilesViewResolver




回答3:


It's a common issue using Spring and it's due to the fact that the view (jsp) goes through the DispatcherServlet.

Try to modify your web.xml using

 <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>/app/*</url-pattern>  
</servlet-mapping>

and then add to your urlrewrite.xml something like:

<urlrewrite default-match-type="wildcard">
<rule>
    <from>/</from>
    <to>/app/</to>
</rule>
<rule>
    <from>/**</from>
    <to>/app/$1</to>
</rule>
<outbound-rule>
    <from>/app/**</from>
    <to>/$1</to>
</outbound-rule>

I'm assuming you're using urlrewrite, if you're not import the jar and add the filter mapping in your web.xml such as:

<filter>
    <filter-name>urlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>urlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping> 


来源:https://stackoverflow.com/questions/2977446/tiles-2-and-no-mapping-found-for-http-request-with-uri-spring-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!