Tiles 2 And No mapping found for HTTP request with

2020-01-29 16:23发布

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 ???

3条回答
你好瞎i
2楼-- · 2020-01-29 16:52

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> 
查看更多
趁早两清
3楼-- · 2020-01-29 16:57

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.

查看更多
相关推荐>>
4楼-- · 2020-01-29 17:02

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:

查看更多
登录 后发表回答