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.Investor; import com.viseur.model.Project; 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 = "MoreSuggestedProjects", urlPatterns = { "/MoreSuggestedProjects" }) public class MoreSuggestedProjects 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<Project> country = new ArrayList<>(); String htmlContent = ""; HttpSession session = request.getSession(); User reg = (User) session.getAttribute("user"); country.addAll(new Investor(reg).getFromInvestorCountry(last)); for (Project proj : country) { htmlContent += "<div class='col-sm-4 col-md-4'><div class='thumbnail'>" + "<h6><span class='label label-default pull-right'>" + proj.categoryName + "</span></h6>" + "<div class='col-item'><div class='photo'><img src='" + VHost.IMGPATH + "/content/logo/" + proj.itemId + ".png' class='img-responsive' alt='' /></div>" + "<div class='info'><div class='row'><div class='price col-sm-12'><div class='separator clear-left'>" + "</div><h4 class=\"text_warap\"><a href='" + VHost.ROOT + "viewproject.jsp?project=" + proj.itemId + "' class='text_warap'>" + proj.title + "</a></h4><p>" + proj.itemShortDesc + "</p></div></div>" + "<div class='separator clear-left'><div class='col-md-6'><h6 class=''><span class='glyphicon glyphicon-eye-open'></span>" + proj.visted + "</h6></div><div class='col-md-6'> <h6 class=''><span class='glyphicon glyphicon-fire'></span> " + proj.buzzedTimes + "</h6></div></div><div class='clearfix'></div></div></div></a></div>"; } json.put("last", last + country.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 "Get More Recent Projects"; } }