Reputation: 47
I am very new to GAE, JDO and JAVA itself and got myself into a NullPointerException while posting my form data to the Servlet. The above code is my JSP file with the Form:
<form action="/todolist" method="POST">
<div class="form-group">
<label for="titel">Titel</label>
<input type="text" class="form-control" id="titel" name="titel" placeholder="Titel">
</div>
<div class="form-group">
<label for="beschreibung">Beschreibung</label>
<input type="text" class="form-control" id="beschreibung" name="beschreibung" placeholder="Beschreibung">
</div>
<div class="form-group">
<label for="duration">Dauer</label>
<input type="text" class="form-control" id="duration" name="duration" placeholder="zB. 2 Wochen...">
</div>
<div class="form-group">
<label for="prio">Priorität</label>
<select class="form-control" id="prio" name="prio">
<option value="1">Priorität 1</option>
<option value="2">Priorität 2</option>
<option value="3">Priorität 3</option>
<option value="4">Priorität "P"</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="save">Save changes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
</div>
This is the Servlet which receives the submitted Fields:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String beschreibung = req.getParameter("beschreibung");
String prio = req.getParameter("prio");
String titel = req.getParameter("titel");
String duration = req.getParameter("duration");
Date termin = new Date();
req.setAttribute("beschreibung", beschreibung);
req.setAttribute("prio", prio);
req.setAttribute("titel", titel);
req.setAttribute("duration", duration);
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory("transactions-optional");
PersistenceManager pm = pmf.getPersistenceManager();
ToDo doing = new ToDo(titel, beschreibung, termin, duration, prio, "super");
try {
pm.makePersistent(doing);
} finally {
pm.close();
}
RequestDispatcher rd = req.getRequestDispatcher("../WEB-INF/index.jsp");
rd.forward(req, resp);
}
UPDATE: I have initialized all my values and am still getting the NullPointerException
Upvotes: 0
Views: 18