java.lang.ClassNotFoundException:spring项目中的org.springframework.web.servlet.DispatcherServlet

Sag*_*ela 0 java

一个hello.jsp

web.xml是

<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version ="3.0">

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- The front controller of this Spring Web application, responsible for 
    handling all application requests -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>

</servlet>

<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

dispatcher-servlet.xml是

<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"

xmlns:p="http://www.springframework.org/schema/p">

<bean id="viewResolver"

    class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix">

        <value>/WEB-INF/jsp/</value>

    </property>

    <property name="suffix">

        <value>.jsp</value>

    </property>

</bean>
<bean name="/hello.html" class="com.spring.HelloWorldController"></bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

JAR文件是:spring.jar spring-webmvc.jar spring-aop spring-beans spring-context spring-context-support spring-core spring-jdbc spring-orm spring-source spring-test spring-tx

Rau*_*ene 8

ClassNotFoundException清楚地表明你缺少org.springframework.web.servlet课程.

如果您不使用Maven,请确保包含所有适当的Spring JAR.

如果您使用的是Maven,请确保包含spring-web依赖项:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version><!-- Your spring version here --></version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

如果这些都不起作用,请看一下这个帖子.