The reference to the EJB, heres the class:
package servlet;
import entity.Persons;
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import session.PersonsFacade;
@WebServlet(name = "Controller", urlPatterns = {"/result"})
public class Controller extends HttpServlet {
@EJB
private PersonsFacade pf; <-- /*This is the reference thats causing
the null pointer exception when its called in the doPost method.*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String userPath = request.getServletPath();
// use RequestDispatcher to forward request internally
String url = "/WEB-INF/view" + userPath + ".jsp";
try {
request.getRequestDispatcher(url).forward(request,
response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
String userPath = request.getServletPath();
request.setAttribute("people", pf.findAll());
if(userPath.equals("/result")){
String firstName = request.getParameter("firstName");
String age = request.getParameter("age");
Persons p = new Persons();
p.setId(1);
p.setFirstName(firstName);
p.setAge(age);
pf.create(p);
}
// use RequestDispatcher to forward request internally
String url = "/WEB-INF/view" + userPath + ".jsp";
try {
request.getRequestDispatcher(url).forward(request,
response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
--
[Message sent by forum member 'asmith2306']
View Post: http://forums.java.net/node/883335