SSM框架启动显示404

我的SSM整合框架项目启动显示404是什么原因呀

img

我把相关配置给你们看
项目结构

img


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:application-*.xml</param-value>
    </context-param>
    <!--    容器加载的监听器-->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <!-- 避免中文乱码 -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

img

img

img

img

img

img

你的web目录 还不是 web资源的根目录, login.jsp 等文件都没有编译到指定输出目录里,也就是打包后的部署包中没有, 这里就访问资源不存在
把 web目录 改成 webapp , 删除.idea目录, 重新按maven导入你的项目, 让idea自动把 相关webapp设置成 web资源根目录

你配置错误,正常这一块需要有个蓝色的点的,表示前端文件夹位置,以及web.xml的根目录位置

img

img

img

img


把这个web.xml文件位置改成你自己的,就可以了

img


蓝色小圆点就会有了,
有效果麻烦给个采纳,谢谢

【以下回答由 GPT 生成】

在项目的web.xml配置文件中,可以看到以下几点需要检查:

  1. DispatcherServlet的servlet-name和servlet-class配置是否正确。在该配置中,servlet-name应该为"DispatcherServlet",servlet-class应该为"org.springframework.web.servlet.DispatcherServlet"。

  2. DispatcherServlet的contextConfigLocation参数值配置是否正确。在该配置中,param-value应该为"classpath:spring-mvc.xml"。确认该文件在正确的路径下。

  3. servlet-mapping中的url-pattern配置是否正确。在该配置中,url-pattern应该为"/",表示将所有的请求都交给DispatcherServlet处理。

  4. context-param中的contextConfigLocation参数值配置是否正确。在该配置中,param-value应该为"classpath:application-*.xml",表示加载类路径下的所有以"application-"开头的xml配置文件。

  5. ContextLoaderListener的listener-class配置是否正确。在该配置中,listener-class应该为"org.springframework.web.context.ContextLoaderListener"。

另外,还需要检查项目结构,确保项目结构中的文件和配置的路径一致。

需要提醒的是,以上只是从配置文件的角度来进行分析,如果未能解决问题,还需要结合具体报错信息和日志来进一步分析错误的根本原因。

希望以上解答对您有所帮助。如果您还有其他问题,请随时提问。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^