這裏是我的控制器方法:Spring MVC中,返回HTML
@RequestMapping(value = "/login/{id}", method = RequestMethod.GET)
public String doLogin(@PathVariable long id, HttpServletRequest request, HttpServletResponse response, Model model) {
logger.info(String.format(
Constants.LogMessages.NEW_GET_REQUEST_FROM_IP,
request.getRemoteAddr()));
logger.info("/login/{id}");
return "login";
}
和我appServlet-context.xml中:
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".html" />
</beans:bean>
的例外,我在這個方法得到的是:
WARN PageNotFound - No mapping found for HTTP request with URI [/project/WEB-INF/views/login.html] in DispatcherServlet with name 'appServlet'
事情是,當我將「後綴」更改爲.jsp和文件的名稱從HTML到.jsp它的作品。
有什麼想法爲什麼?
編輯:
這裏是我的web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<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-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
<filter-name>cors</filter-name>
<filter-class>src.com.project.context.CorsFilter</filter-class>
<filter-name>cors</filter-name>
<url-pattern>/*</url-pattern>
項目是否存在文件'/項目/ WEB-INF /視圖/ login.html'? –
是文件存在。 – Urbanleg
您可以在web.xml中顯示DispatcherServlet的配置。 –