【问题标题】:spring mvc when using *.jsp in urlpattern in web.xml file shows 404 and in console noHandlerFoundspring mvc 在 web.xml 文件中的 urlpattern 中使用 *.jsp 时显示 404 并且在控制台 noHandlerFound
【发布时间】:2017-06-25 09:09:29
【问题描述】:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>changeinwebxmlinurlpattern</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>


  <servlet>
    <servlet-name>sample</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>sample</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>

</web-app>

因为欢迎文件是 index.jsp 但该请求是 noHandlerFound 意味着请求正在搜索必须返回 index.jsp 的控制器。如果它是使用欢迎文件的人。或者我犯了什么错误

【问题讨论】:

  • 但是 index.jsp 将如何调用

标签: java spring spring-mvc servlets spring-boot


【解决方案1】:

将您的url-pattern 更改为/,您应该将您的调度程序servlet 称为dispatcher。这是我项目中的一个示例:

   <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

【讨论】:

  • 那不是我的问题,我的问题是当我使用 *.jsp 时,如果我会使用它会正常工作。
猜你喜欢
  • 2017-11-24
  • 2017-10-25
  • 2013-03-27
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 2013-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多