Created
January 3, 2014 10:11
-
-
Save rominirani/8235732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Java Servlet, mapped to '/AddEmployee' endpoint and used by the addemployee.jsp page to add sample employees to the | |
* Index. | |
*/ | |
package com.mindstorm.employeesdirectory.servlets; | |
import java.io.IOException; | |
import javax.servlet.http.*; | |
import com.mindstorm.employeesdirectory.utils.ImportEmployeesIntoIndex; | |
@SuppressWarnings("serial") | |
public class AddEmployeeServlet extends HttpServlet { | |
/** | |
* The GET method extracts out the JSON formatted Contact data provided. It will call the utility method in the | |
* ImportContactsIntoIndex class to process the Records and add them to the Index. | |
*/ | |
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | |
resp.setContentType("text/html"); | |
try { | |
String employeeJSONData = req.getParameter("employeeJSONData"); | |
if (employeeJSONData != null) { | |
ImportEmployeesIntoIndex.processEmployees(employeeJSONData); | |
resp.getWriter().println("Employees have been added to the Index"); | |
resp.getWriter().println("<a href='employees.jsp'>Back to Search Page</a> | <a href='addemployee.jsp'>Add More Employees</a>"); | |
} | |
} | |
catch (Exception ex) { | |
resp.getWriter().println("Error importing employees. Reason : " + ex.getMessage()); | |
resp.getWriter().println("<a href='employees.jsp'>Back to Search Page</a> | <a href='addemployee.jsp'>Add More Employees</a>"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment