我有一个使用瓷砖作为 UI 框架的春季项目。我想提供一个处理静态 html 文件的通用控制器(没有动态内容 - 所以没有自定义控制器)。通用控制器是org.springframework.web.servlet.mvc.UrlFilenameViewController
. 如果我将静态内容放在.jsp
扩展文件中,那么整个事情都会起作用。只要我尝试将它们放入.html
- 我会收到 404 错误,我想找出原因。
网页.xml:
<display-name>
lyricsBase
</display-name>
<servlet>
<servlet-name>lyricsBaseApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lyricsBaseApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>list.html</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/jsp/404.jsp</location>
</error-page>
歌词BaseApp-servlet.xml:
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="staticViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController">
<property name="prefix" value="t." />
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/list.html">jukeboxController</prop>
<prop key="/display.html">songController</prop>
<prop key="/static/about.html">staticViewController</prop>
</props>
</property>
</bean>
瓷砖.xml:
<definition name="t.base" template="/WEB-INF/tiles/base.jsp">
<put-attribute name="title" value="SomeTitle"/>
</definition>
<definition name="t.static/about" extends="t.base">
<put-attribute name="body" value="/WEB-INF/static/about.jsp"/>
<put-attribute name="title" expression="about"/>
</definition>
这是我访问静态页面的 URL:http://localhost:8084/lyricsBase/static/about.html
我在正确的目录中都有about.html
和about.jsp
文件。如果一个
<put-attribute name="body" value="/WEB-INF/static/about.jsp"/>
至
<put-attribute name="body" value="/WEB-INF/static/about.html"/>
我开始在tomcat中收到警告:
2013-02-16 18:21:45 org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/lyricsBase/WEB-INF/static/about.html] in DispatcherServlet with name 'lyricsBaseApp'
为什么?