java.lang.NumberFormatException: null problème ParseInt
Salut je développe un code qui ajoute une formation dans la base de donnée. j'utilise jee (jsp, servlet) et je n'arrive pas à comprendre le problème lorsqu'il s'agit de la récupération d'un paramètre entier.
voila me code de ma servlet:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| package sevlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import modele.Formation;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import services.FormationServices;
public class AjoutFormation extends HttpServlet {
private static final long serialVersionUID = 1L;
private static SessionFactory sessionFactory;
// Si on tente d'accéder directement à la Servlet, on redirige vers
// ajoutFormation.jsp
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
getServletContext().getRequestDispatcher("/ajoutFormation.jsp")
.forward(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// Récupération des données du formulaire d'ajoutFormation.jsp
FormationServices frServices = new FormationServices();
String titre = request.getParameter("titre");
String thème = request.getParameter("thème");
String formateur = request.getParameter("formateur");
String date_deb = request.getParameter("date_deb");
String date_fin = request.getParameter("date_fin");
int durée = request.getIntHeader("durée");
String prix_indiv = request.getParameter("prix_indiv");
String prix_gpe = request.getParameter("prix_gpe");
int nbre_place = request.getIntHeader("nbre_place");
System.out.println("données lu" + titre);
if (!"".equals(titre) && !"".equals(thème) && !"".equals(formateur)
&& !"".equals(nbre_place) && !"".equals(durée)
&& !"".equals(prix_indiv) && !"".equals(prix_gpe)
&& !"".equals(date_deb) && !"".equals(date_fin)) {
// Create the SessionFactory from hibernate.cfg.xml
System.out.println("condition vérifiée");
durée = Integer.parseInt(request.getParameter("durée"));
nbre_place = Integer.parseInt(request.getParameter("nbre_place"));
sessionFactory = new AnnotationConfiguration().configure()
.buildSessionFactory();
Formation fr = new Formation(titre, thème, nbre_place, formateur,
prix_gpe, prix_indiv, date_deb, date_fin, durée);
Session s = getSession();
Transaction t = s.beginTransaction();
s.save(fr);
t.commit();
s.close();
getServletContext().getRequestDispatcher("/Confirmer_ajout.jsp")
.forward(request, response);
}
}
public static Session getSession() {
return sessionFactory.openSession();
}
} |
et voila l'erreur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Infos: Server startup in 11510 ms
données luhello
condition vérifiée
oct. 08, 2012 1:03:17 AM org.apache.catalina.core.StandardWrapperValve invoke
Grave: "Servlet.service()" pour la servlet AjoutFormation a généré une exception
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at sevlets.AjoutFormation.doPost(AjoutFormation.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source) |
Pouvez vous m'aider? et merci :)