Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.viseur.control; import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONException; import org.json.JSONObject; import com.viseur.model.DeveloperItems; /** * * @author JHK */ public class SearchDevItems extends HttpServlet { /** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject obj = new JSONObject(); try { obj.put("success", 0); } catch (JSONException ex) { } Enumeration<String> names = request.getParameterNames(); String para = names.nextElement(); String val = request.getParameter(para); DeveloperItems itm = new DeveloperItems(); switch (para) { case "lang": obj = new JSONObject(itm.getProgrammingLangs(val)); break; case "opsys": obj = new JSONObject(itm.getOpSystems(val)); break; case "platform": obj = new JSONObject(itm.getPlatforms(val)); break; } response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); try (PrintWriter out = response.getWriter()) { out.println(obj); } } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Search for Developer Items"; } }