【问题标题】:Spring MVC, Returning HTMLSpring MVC,返回 HTML
【发布时间】:2013-08-23 16:07:33
【问题描述】:

这是我的控制器方法:

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

【问题讨论】:

  • 项目中是否存在文件/project/WEB-INF/views/login.html
  • 能否请您在 web.xml 中显示您的 DispatcherServlet 配置。
  • 当然!张贴在原始消息中
  • 你使用的是什么服务器?雄猫?

标签: html spring jsp spring-mvc


【解决方案1】:

在您的 .xml 文件中尝试更改:

<servlet-name>appServlet</servlet-name>

<url-pattern>/</url-pattern>

收件人:

<servlet-name>appServlet</servlet-name>

<url-pattern>*.html</url-pattern>

【讨论】:

    【解决方案2】:

    只是一个想法。可能是您的构建过程没有将 /project/WEB-INF/views/login.html 文件复制到战争中。取消战争并检查是否存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 2016-11-23
      • 2015-08-16
      相关资源
      最近更新 更多