【问题标题】:HTTP Status 500 - Servlet.init() for servlet spring-dispatcher threw exception_(spring-dispatcher-servlet is good)HTTP 状态 500 - servlet spring-dispatcher 的 Servlet.init() 抛出异常_(spring-dispatcher-servlet 很好)
【发布时间】:2019-07-29 17:40:04
【问题描述】:

我上次运行代码时正在为大学创建一个示例网站,但运行良好,但一段时间后运行它时出现此错误 “HTTP 状态 500 - servlet spring-dispatcher 的 Servlet.init() 抛出异常”

错误信息 -

输入异常报告

servlet spring-dispatcher 的消息 Servlet.init() 抛出异常

描述服务器遇到阻止它的内部错误 完成此请求。

异常

javax.servlet.ServletException: Servlet.init() 用于 servlet spring-dispatcher 抛出异常 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

java.lang.Thread.run(Thread.java:748)

以下是我正在研究的课程

spring-dispatcher-servlet.xml -

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


    <context:component-scan base-package="com.newseries.hecontroller" />
    <mvc:annotation-driven/>    

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

studentAdmissionController -

包 com.newseries.hecontroller;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.text.DateFormat;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class studentAdmissionController {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        //binder.setDisallowedFields(new String[] {"mobileNumber"});
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy****MM**dd");
        binder.registerCustomEditor(Date.class, "newDate", new CustomDateEditor(sdf, false));
        //binder.registerCustomEditor(String.class, "firstName", new StudentNameEditor());
    }

    @RequestMapping(value="/admissionForm.html", method = RequestMethod.GET)
    public ModelAndView getAdmissionForm() {
        ModelAndView model = new ModelAndView("AdmissionForm");
        return model;
    }

    @ModelAttribute
    public void addcommonmethod(Model model) {
        model.addAttribute("headermessage", "SIT college of Engineering India");
    }

    @RequestMapping(value="/submitAdmissionForm.html", method = RequestMethod.POST)
    public ModelAndView submitAdmissionForm(@ModelAttribute("student1") Student student1, BindingResult result) {

        if(result.hasErrors()) {
            ModelAndView model1 = new ModelAndView("AdmissionForm");
            return model1;
        }

        ModelAndView model = new ModelAndView("AdmissionSuccess");
        return model;
 }
}

AdmissionForm.jsp -

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<body>
    <h1>${headermessage}</h1>
    <h2>College Admission Courses</h2>

    <form:errors path="student1.*"/>

    <form action="/FirstSpringMVCApplication02/submitAdmissionForm.html"
        method="post">
<table>
<tr> <td>Student's FirstName    :   </td> <td>   <input type="text" name="firstName" /> </td> </tr>
<tr> <td>Student's LastName     :   </td> <td>   <input type="text" name="lastName"  /> </td> </tr>
<tr> <td>Student's Hobby        :   </td> <td>   <input type="text" name="studentHobby" /> </td> </tr>
<tr> <td>Student's MobileNumber :   </td> <td>   <input type="text" name="mobileNumber" /> </td> </tr>
<tr> <td>Student DOB            :   </td> <td>   <input type="text" name="newDate" /> </td> </tr>
<tr> <td>Student skillSet       :   </td> <td>   <select name="studentSkills" multiple>
                                                 <option value="CoreJava">Core Java</option>
                                                 <option value="SpringMVC">SpringMVC</option>
                                                 <option value="SpringIOC">SpringIOC</option>
                                                 <option value="SpringAOP">SpringAOP</option>
                                                 <option value="SpringDAO">SpringDAO</option>
                                                 <option value="SpringBoot">SpringBoot</option>
                                                 <option value="Multithreading">Multithreading</option>
                                                 <option value="Collection">Collection</option>
                                                 <option value="Oops">Oops</option>
                                                 <option value="Hibernate">Hibernate</option> 
                                                 </select></td> </tr>
</table>
        <table>
            <tr>
                <td>Student's Address :</td>
            </tr>

            <tr>
                <td>Country: <input type="text" name="studentAddress.country" /></td>
                <td>City : <input type="text" name="studentAddress.city" /></td>
                <td>Street : <input type="text" name="studentAddress.city" /></td>
                <td>pinCode: <input type="text" name="studentAddress.pinCode" /></td>
            </tr>

        </table>

        <input type="submit" value="Submit" />
    </form>

</body>
</html>

web.xml -

<?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>FirstSpringMVCApplication02</display-name>

  <servlet>
  <servlet-name>spring-dispatcher</servlet-name>
  <servlet-class>
  org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  </servlet>

  <servlet-mapping>
  <servlet-name>spring-dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

AdmisssionSuccess.jsp -

<html>
<body>

    <h1>${headermessage}</h1>

    <h2>Congrats!! The Engineering college has processed the
        application Successfully</h2>

    <h3>Details submitted by you are: :</h3>

    <table>

        <tr>
            <td>Student_FirstName : </td>
            <td>${student1.firstName}</td>
        </tr>

        <tr>
            <td>Student_LastName : </td>
            <td>${student1.lastName}</td>
        </tr>

        <tr>
            <td>Students_Hobby : </td>
            <td>${student1.studentHobby}</td>
        </tr>

        <tr>
        <td>Student's_MobileNumber : </td>
        <td>${student1.mobileNumber}</td>
        </tr>

        <tr>
        <td>Student's_DOB : </td>
        <td>${student1.newDate}</td>
        </tr>

        <tr>
        <td>Student's_skills : </td>
        <td>${student1.studentSkills}</td>
        </tr>

        <tr>
        <td>Student's Address : </td>
        <td>country : ${student1.studentAddress.country}
            city    : ${student1.studentAddress.city}
            street  : ${student1.studentAddress.street}
            pincode : ${student1.studentAddress.pinCode}</td>
        </tr>


    </table>


</body>
</html>

【问题讨论】:

  • 那个堆栈跟踪看起来被截断了。它缺少引发实际异常的“原因”。

标签: java html spring spring-mvc servlets


【解决方案1】:

将此参数添加到 web.xml 文件中

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
</context-param>

【讨论】:

  • 感谢您的回答 Rathnayake,问题已解决,与服务器有关。我已将 tomcat 服务器从版本 7 更改为 8。
猜你喜欢
  • 1970-01-01
  • 2023-03-24
  • 2013-02-04
  • 1970-01-01
  • 2017-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-21
相关资源
最近更新 更多