I'm trying to redirect to another page from my servlet where string value is null. When I run the code it stays on the same page instead of redirecting to my error page. Here is my code:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType("text/html");
String emp = request.getParameter("emp")!=null ? request.getParameter("emp"): "";
MCenter mCenter = new MCenter();
mCenter = mCenterDAO.getMCenterPocByEmp(emp);
mCenter = mCenterDAO.getMCenterByObject(mCenter);
PrintWriter pw = response.getWriter();
String mPocName = mCenter.getMCenterPocName();
String mCenter = mCenter.getMCenterName();
if(mPocName == null || mCenter == null) {
request.getRequestDispacher("error.jsp").forward(request, response);
System.out.println("Null or not name " + mPocName + "center " + mCenter);
}
String json = getMCenterPoc(emp);
pw.print(json);
pw.close();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
doPost(request, response);
}
I get no error, and the print out give me null or value depending on whether or not there is value or not.