我正在使用Spring MVC开发一个项目。 我创建了许多工作正常的CRUD。但对于那个,保存不起作用。我有两个课程考试和问题。我选择考试,然后在表格中为此考试添加问题。 错误是:
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
cause mère
java.lang.NullPointerException
org.inpt.elearning.controllers.ExpertController.saveQuestionExam(ExpertController.java:175)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
我控制器中的方法:
@RequestMapping(value="/saveQuestionExam")
public String saveQuestionExam(Question q,Model model){
if(q.getId_question()!=null){
metier.modifierQuestion(q);
}
else
metier.ajouterQuestion(q,q.getExamQuestion().getIdExam());
model.addAttribute("question",new Question());
model.addAttribute("questions",metier.listQuestionParExam(q.getExamQuestion().getIdExam()));
model.addAttribute("exams",metier.listExam());
return "ajouterQuestions";
}
我的ajouterQuestions.jsp文件:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<head>
<link rel="stylesheet" type="text/css" href=" <%=request.getContextPath()%>/resources/css/style1.css" >
</head>
<div id="formQuestionExam" class="cadre">
<f:form modelAttribute="question" action="saveQuestionExam"
method="post" enctype="multipart/form-data">
<table>
<tr>
<td>ID question</td>
<td><f:input path="id_question"/></td>
<td><f:errors path="id_question" cssClass="errors"></f:errors> </td>
</tr>
<tr>
<td>Formulation</td>
<td><f:textarea path="formulation"/></td>
<td><f:errors path="formulation" cssClass="errors"></f:errors></td>
</tr>
<tr>
<td>Choix 1</td>
<td><f:input path="choix1_question" /></td>
<td><f:errors path="choix1_question" cssClass="errors"> </f:errors></td>
</tr>
<tr>
<td>Choix 2</td>
<td><f:input path="choix2_question" /></td>
<td><f:errors path="choix2_question" cssClass="errors"></f:errors></td>
</tr>
<tr>
<td>Choix 3</td>
<td><f:input path="choix3_question" /></td>
<td><f:errors path="choix3_question" cssClass="errors"></f:errors></td>
</tr>
<tr>
<td>La réponse correcte</td>
<td><f:input path="rep_correcte" /></td>
<td><f:errors path="rep_correcte" cssClass="errors"></f:errors></td>
</tr>
<tr>
<td><input type="submit" value="Save"/></td>
</tr>
</table>
</f:form>
</div>
<div id="tabCours" class="cadre">
<table class="tab1">
<tr>
<th>ID</th><th>Formulation</th><th>choix1</th><th>Choix2</th>< th>choix3</th><th>Réponse correcte</th>
</tr>
<c:forEach items="${questions}" var="q">
<tr>
<td>${q.id_question}</td>
<td>${q.formulation}</td>
<td>${q.choix1_question}</td>
<td>${q.choix2_question}</td>
<td>${q.choix3_question}</td>
<td>${q.rep_correcte}</td>
<td><a href="suppQuest?id_question=${q.id_question}">Supprimer</a></td>
<td><a href="editQuest?id_question=${q.id_question}">Editer</a> </td>
</tr>
</c:forEach>
</table>