考虑以下Controller
@Controller
public class HomeController {
@RequestMapping(value="/")
public ModelAndView home() {
ModelAndView model = new ModelAndView("index");
return model;
}
这是我的servlet-context.xml
:
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".html" />
</bean>
这是我的web.xml
:
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
每次我点击网址时都会收到此消息:
Aug 08, 2015 10:59:47 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'
Aug 08, 2015 10:59:48 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/MeraComputer/WEB-INF/views/index.html] in DispatcherServlet with name 'appServlet'
我想,我的文件夹结构也很好,
答案 0 :(得分:0)
我认为静态html文件不能用作视图。该请求被转发到视图,即/MeraComputer/WEB-INF/views/index.html
,并且因为它是静态文件而不是请求处理程序,您可能会收到警告。
应以不同方式处理静态文件。我认为This is类似的帖子可能有所帮助。