List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:com.alcshare.gothere.servlets.SearchServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/json"); final String value = req.getParameter(PARAM_VALUE); if (req.getParameter(PARAM_REINIT) != null) req.getSession().removeAttribute(KEY_DATA); final PrintWriter writer = resp.getWriter(); try {//from w ww. j a va2 s .c om LDSearch searcher = getSearch(req); //Date start = new Date(); List<LocationInfo> result = searcher.search(value, 250); //Date end = new Date(); //System.out.println("Searching for '" + value + "' took " + (end.getTime() - start.getTime()) + " mSec."); writeResults(result, writer); } catch (Exception e) { LOGGER.println(e); } }
From source file:com.luis.controllers.ServletController.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w. jav a 2 s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); BeanDatosExcel datosExcel = new BeanDatosExcel(); Excel mi_clase_excel = new Excel(); String ruta = mi_clase_excel.guardarArchivo(request); if (!ruta.equals("-1")) { datosExcel.setMiExcel(mi_clase_excel.leerExcel(ruta)); System.out.println("------------------------********************---------"); if (datosExcel.getMiExcel() != null) { request.setAttribute("datosExcel", datosExcel); request.getRequestDispatcher("recepcionExcel.jsp").forward(request, response); } else { request.getRequestDispatcher("salida.jsp").forward(request, response); } } else { System.out.println("Noooooooooooooooooooooooooooooooooooooooooooop"); request.getRequestDispatcher("salida.jsp").forward(request, response); } }
From source file:add.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a va 2s . c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); EmployeeJDBCTemplate employeeJDBCTemplate = (EmployeeJDBCTemplate) context.getBean("employeeJDBCTemplate"); System.out.println("Creating Records..."); employeeJDBCTemplate.create(request.getParameter("name"), request.getParameter("email"), request.getParameter("mobile"), request.getParameter("department"), request.getParameter("salary")); URL obj = new URL("http://shashankgaurav.com/sendmail.php?email=" + request.getParameter("email")); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); int responseCode = con.getResponseCode(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("Created"); } }
From source file:redeemCoupon.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. j a v a 2 s .com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String deviceId = request.getParameter("deviceId"); String couponId = request.getParameter("couponId"); String tranToken = request.getParameter("tranToken"); String url = "https://tgl.standardchartered.com/bridgeheadi18n/mcoupon/redeem?deviceId=" + deviceId + "&couponId=" + couponId + "&TT=" + tranToken; HttpClient client = new DefaultHttpClient(); HttpGet req = new HttpGet(url); HttpResponse res = client.execute(req); BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent())); String line = ""; String total = ""; while ((line = rd.readLine()) != null) { total += line; } total = total.substring(0, total.length()); out.println(total); } }
From source file:controller.getReview.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww. j av a 2 s .c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); }
From source file:com.bounswe2015group5.xplore.AllCommentsServlet.java
/** * Returns all comments of a contribution as an array of JSONObjects. * Each object includes content, and date of the comment with * its creator's name and surname./* www . ja v a2 s .com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs * @author Can Guler */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String contribId = request.getParameter("contribId"); out.print(getAllComments(contribId).toString()); } }
From source file:br.com.munif.personalsecurity.aplicacao.autorizacao.GenericTokenApi.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json;charset=UTF-8"); List<Usuario> todos = service.findAll(); Usuario usuario = todos.get(0);//from w w w .j a v a 2 s . c o m mapper.writeValue(response.getOutputStream(), TokenAdapter.getLoginData(usuario)); }
From source file:com.arifultonu.mappingServlet.LoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www . j a va2s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet LoginServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet LoginServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); } }
From source file:cs472.w1d5.servlet.Welcome.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w. j a v a 2s . com * @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 { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet AddUser</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>We only process GET requests</h1>"); out.println("</body>"); out.println("</html>"); } }