我上次运行代码时,我正在为College创建一个示例网站,该网站运行良好,但是一段时间后运行时,出现此错误 “ HTTP状态500-Servlet弹簧调度程序的Servlet.init()抛出异常”
错误消息-
类型异常报告
用于servlet spring-dispatcher的消息Servlet.init()抛出异常
说明服务器遇到内部错误,阻止了它 满足此请求。
例外
javax.servlet.ServletException:Servlet的Servlet.init() 春季调度员抛出异常 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 -
package 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>
AdmissionsionSuccess.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>
答案 0 :(得分:0)
将此参数添加到web.xml文件中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-dispatcher-servlet.xml</param-value>
</context-param>