我得到一个HTTP状态500 - servlet HelloWorld的Servlet.init()抛出异常

时间:2016-05-31 06:09:55

标签: spring spring-mvc

查看“Servlet.init()for servlet”的其他帖子没有帮助。  这不是Maven或Gradle,所以没有pom.This是一个简单的简单的春季项目,我仍然在努力。片段下方是实际错误。

Hellocontroller.java。

package controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.*;

//import com.sun.javafx.collections.MappingChange.Map;

public class Hellocontroller implements Controller {

    @Override
    public ModelAndView handleRequest(HttpServletRequest req,
            HttpServletResponse res) throws Exception {

           String name = req.getParameter("name");

           Map m = new HashMap();
           m.put("msg", "Hello ...."+name);                             

           ModelAndView mav =new ModelAndView("success",m);

        return mav;
    }

}

的HelloWorld-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">



    <bean name="./hello.ds" class="controller.Hellocontroller">
    </bean>

    <bean class="org.springframework.web.servlet.InternalViewResolver">
        <property name="prefix" value="/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    </servlet>


    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>*.ds</url-pattern>
    </servlet-mapping>
</web-app>

的success.jsp

${msg}

的index.jsp

<h1>HelloWorld</h1>

<form action ="./hello.ds">

NAME:<input type = "text" name="name">

SUBMIT<input type = "submit" value="sayHello">


</form>

错误:

type Exception report

message Servlet.init() for servlet HelloWorld threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

例外

javax.servlet.ServletException: Servlet.init() for servlet HelloWorld threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501


root cause 

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.web.servlet.InternalViewResolver] for bean with name 'org.springframework.web.servlet.InternalViewResolver#0' defined in ServletContext resource [/WEB-INF/HelloWorld-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.InternalViewResolver
    org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1208)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:570)
    org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1277

1 个答案:

答案 0 :(得分:0)

您的配置出错。类org.springframework.web.servlet.InternalViewResolver不存在(你可以从一个古老的mvc例子中复制/粘贴它吗?)。

尝试将其替换为org.springframework.web.servlet.view.InternalResourceViewResolver。我不能保证它有效,但值得尝试。