eclipse中springmvc框架出现404

时间:2024-01-25 21:15:27

出现404报错信息:

1.我出现的错误是配置没问题,找了一圈发现自己单词拼错了,导致运行不了,出现404

2.配置问题:

jar包:首先导入spring 的jar包15个,log4j两个,junit两个。(我是直接在电脑上建了一个文件夹,用的时候直接复制粘贴,不用每次来回倒)

配置文件:log4j.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- status=debug 可以查看log4j的装配过程 -->
<configuration status="off" monitorInterval="1800">
    <appenders>
        <!-- 定义控制台输出 -->
        <Console name="Console" target="SYSTEM_OUT" follow="true">
            <PatternLayout
                pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
        </Console>

        <RollingRandomAccessFile name="System"
            fileName="logs/mvchain/system.log" filePattern="logs/mvchain/system_%d{yyyy-MM-dd}_%i.log">
            <PatternLayout
                pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
            <Policies>
                <!-- 多长时间生成一个文件;默认1天 -->
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
                <!-- 多大的文件要切分 -->
                <SizeBasedTriggeringPolicy size="5K" />
            </Policies>
        </RollingRandomAccessFile>

        <!-- 外部打印日志 -->
        <RollingRandomAccessFile name="Outer"
            fileName="logs/mvchain/outer.log" filePattern="logs/mvchain/outer_%d{yyyy-MM-dd}_%i.log">
            <PatternLayout
                pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
                <SizeBasedTriggeringPolicy size="100M" />
            </Policies>
        </RollingRandomAccessFile>

        <!-- 线程打印日志 -->
        <RollingRandomAccessFile name="Timer"
            fileName="logs/mvchain/timer.log" filePattern="logs/mvchain/timer_%d{yyyy-MM-dd}_%i.log">
            <PatternLayout
                pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
                <SizeBasedTriggeringPolicy size="100M" />
            </Policies>
        </RollingRandomAccessFile>
    </appenders>
    <loggers>
        <!-- Root Logger(这个是整个配置文件的入口 -->
        <root level="trace">
            <!-- 调用定义的log4j配置
                console:指的是名字;(在这个标签中定义configuration==>appenders这下面标签的name属性 )
             -->
            <appender-ref ref="Console" />
            <appender-ref ref="System" />
        </root>

        <!-- 外部日志,分开日志,name为getLogger()
            console:指的是名字;(在这个标签中定义configuration==>appenders这下面标签的name属性 )
            下面定义的多个组合,logger标签中任意组合
         -->
        <logger name="SystemLog" level="info" additivity="false">
            <appender-ref ref="Console" />
            <appender-ref ref="System" />
        </logger>

        <!-- 外部日志,分开日志,name为getLogger() -->
        <logger name="OuterLog" level="info" additivity="false">
            <!-- 日志文件要输出到三个地方,控制台,系统文件,外部文件 -->
            <appender-ref ref="Console" />
            <appender-ref ref="System" />
            <appender-ref ref="Outer" />
        </logger>

        <!-- 线程日志,分开日志,name为getLogger() -->
        <logger name="TimerLog" level="info" additivity="false">
            <!-- 日志文件要输出到三个地方,控制台,系统文件,外部文件 -->
            <appender-ref ref="Console" />
            <appender-ref ref="System" />
            <appender-ref ref="Outer" />
        </logger>
    </loggers>
</configuration>
log4j

 

web.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 4     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
 5     id="WebApp_ID" version="4.0">
 6  <display-name>01_spring_mvc2</display-name>
 7   <!-- 配置开始 -->
 8   <servlet>
 9    <servlet-name>DispatcherServlet</servlet-name>
10     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
11     <!-- 一起动就初始化此servlet,数字小的先加载,大的后加载 -->
12     <init-param>
13       <param-name>contextConfigLocation</param-name>
14      <param-value>classpath*:applicationContext_*.xml</param-value>
15     </init-param>
16     
17     <load-on-startup> 1</load-on-startup>
18   </servlet>
19   
20   <servlet-mapping>
21      <servlet-name>DispatcherServlet</servlet-name>
22      <!-- 所有url启动要以htm结尾才会访问此servlet -->
23      <url-pattern>*.htm</url-pattern>
24 
25   </servlet-mapping>
26   <!-- 配置结束 -->
27   
28   <welcome-file-list>
29     <welcome-file>index.html</welcome-file>
30     <welcome-file>index.htm</welcome-file>
31     <welcome-file>index.jsp</welcome-file>
32     <welcome-file>default.html</welcome-file>
33     <welcome-file>default.htm</welcome-file>
34     <welcome-file>default.jsp</welcome-file>
35   </welcome-file-list>
36 </web-app>
web.xml

 

index.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5     <head>
 6         <meta charset="UTF-8">
 7         <title>首页</title>
 8     </head>
 9     <body>
10        <!-- 项目命 -->
11         ${pageContext.request.contextPath }
12         <table  border="1"style="width:80%">
13             <tr>
14                
15                <td>名字</td>
16                <td>连接</td>
17             </tr>
18             
19             <tr>
20                
21                <td>xml</td>
22                <td>
23                <a  href="${pageContext.request.contextPath}/xmlController.htm" target="_blank">xml</a>
24                </td>
25             </tr>
26             <tr>
27                
28                <td>anno</td>
29                <td><a  href="${pageContext.request.contextPath}/test1.htm" target="_blank">anno</a></td>
30             </tr>
31             
32             <tr>
33                
34                <td>anno2</td>
35                <td><a  href="${pageContext.request.contextPath}/test2.htm" target="_blank">anno2</a></td>
36             </tr>
37            
38         
39         </table>
40     
41     </body>
42 </html>
index.jsp

 

applicationContext_common.xml:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:aop="http://www.springframework.org/schema/aop"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans
 7         https://www.springframework.org/schema/beans/spring-beans.xsd
 8         http://www.springframework.org/schema/context
 9         https://www.springframework.org/schema/context/spring-context.xsd
10         http://www.springframework.org/schema/aop
11         https://www.springframework.org/schema/aop/spring-aop.xsd">
12     <context:component-scan
13         base-package="conttroller"></context:component-scan>
14 
15     <bean id="xmlController" name="/xmlController.htm"
16         class="conttroller.XmlController">
17     </bean>
18 
19 
20 </beans>
applicationContext_common.xml

另外还需要一个Java文件和jsp就不粘贴