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 com.viseur.model.Developer; import com.viseur.model.Idea; import com.viseur.model.User; import com.viseur.model.VHost; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; 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 javax.servlet.http.HttpSession; import org.json.JSONObject; /** * * @author JHK */ @WebServlet(name = "MoreTailoredIdeas", urlPatterns = { "/MoreTailoredIdeas" }) public class MoreTailoredIdeas extends HttpServlet { /** * Handles the HTTP <code>GET</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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONObject json = new JSONObject(); int last = Integer.valueOf(request.getParameter("last")); ArrayList<Idea> suggested = new ArrayList<>(); String htmlContent = ""; HttpSession session = request.getSession(); User reg = (User) session.getAttribute("user"); suggested.addAll(new Developer(reg).getRelativeIdeas(last)); for (Idea ideaN : suggested) { String tags = ""; if (!ideaN.oSys.isEmpty()) { for (int key : ideaN.oSys.keySet()) { tags += "<label class='label label-info'>" + ideaN.oSys.get(key) + "</label> "; } } if (!ideaN.langs.isEmpty()) { for (int key : ideaN.langs.keySet()) { tags += "<label class='label label-default'> " + ideaN.langs.get(key) + "</label> "; } } if (!ideaN.platforms.isEmpty()) { for (int key : ideaN.platforms.keySet()) { tags += "<label class='label label-primary'>" + ideaN.platforms.get(key) + "</label> "; } } htmlContent += "<div class='col-sm-6 col-md-4'><div class='thumbnail'><h6><span class='label label-default pull-right'>" + ideaN.ideaStatus + "</span></h6><div class='caption'><div class='row'>" + "<div class='col-md-12 col-xs-12 idea_title'><h3>" + ideaN.title + "</h3></div></div>" + "<p class='idea_desc'>" + ideaN.itemShortDesc + "</p><div class='row'><div class='col-md-6'><h6 class=''>" + "<span class='glyphicon glyphicon-eye-open'></span>" + ideaN.visted + "VIEWS</h6></div>" + "<div class='col-md-6'><h6 class=''><span class='glyphicon glyphicon-fire'></span>" + ideaN.buzzedTimes + "BUZZES</h6></div></div><div class='row'><div class='col-md-12'>" + tags + "</div></div></div><a href='" + VHost.ROOT + "/viewidea.jsp?idea=" + ideaN.itemId + "' class='btn btn-primary btn-block'>" + " View</a></div></div>"; } json.put("last", last + suggested.size()); json.put("htmlContent", htmlContent); try (PrintWriter out = response.getWriter()) { out.println(json); out.flush(); } } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "More Developer Tailored Proejcts"; }// </editor-fold> }