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 AddDevItems 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", 2); } 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.addProgrammingLang(val)); break; case "opsys": obj = new JSONObject(itm.addOpSystem(val)); break; case "platform": obj = new JSONObject(itm.addPlatform(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 "Adding Values To Project Details"; }// </editor-fold> }