List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:fr.penet.servlet.ResumeCrawlServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); String runIdString = req.getParameter("id"); if (StringUtils.isEmpty(runIdString)) { resp.getWriter().println("Error : empty id parameter"); return;/*from w w w .j a v a2 s. co m*/ } if (!StringUtils.isNumeric(runIdString)) { resp.getWriter().println("Error : id parameter is not an integer"); return; } int runId = Integer.parseInt(runIdString); String threads = req.getParameter("threads"); int threadInt = 5; if (StringUtils.isNumeric(threads)) { threadInt = Integer.parseInt(threads); } CustomCrawler crawler = new CustomCrawler(); crawler.resumeCollectUrls(runId, threadInt); resp.getWriter().println("Crawler run with id " + runId + " resumed with " + threadInt + " threads"); }
From source file:com.geocent.owf.openlayers.handler.DefaultHandler.java
@Override public String handleContent(HttpServletResponse response, InputStream responseStream) throws IOException { response.setContentType(contentType); return IOUtils.toString(responseStream); }
From source file:ManualInvalidate.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); HttpSession session = req.getSession(); // Invalidate the session if it's more than a day old or has been // inactive for more than an hour. if (!session.isNew()) { // skip new sessions Date dayAgo = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000); Date hourAgo = new Date(System.currentTimeMillis() - 60 * 60 * 1000); Date created = new Date(session.getCreationTime()); Date accessed = new Date(session.getLastAccessedTime()); if (created.before(dayAgo) || accessed.before(hourAgo)) { session.invalidate();// www .j a v a 2 s . c o m session = req.getSession(); // get a new session } } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); // Get the current session object, create one if necessary HttpSession session = req.getSession(); // Add a CustomBindingListener session.setAttribute("bindings.listener", new CustomBindingListener(getServletContext())); out.println("This page intentionally left blank"); }
From source file:JapaneseHelloWorldServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); response.setLocale(Locale.JAPANESE); PrintWriter out = response.getWriter(); out.println("<FONT SIZE=+2>"); out.println("\u4eca\u65e5\u306f\u4e16\u754c"); out.println("</FONT>"); }
From source file:Main.java
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // Print out the IP address of the caller out.println(request.getRemoteAddr()); }
From source file:simplestorage.hashtable.JsonView.java
@Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/plain"); response.setHeader("Cache-Control", "no-cache"); String json = model.get("responseJson").toString(); ServletOutputStream out = response.getOutputStream(); out.print(json);/*from w w w . java2 s . c om*/ out.close(); }
From source file:InitParamServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); String url = getInitParameter("URL"); ServletConfig config = getServletConfig(); ServletContext context = getServletContext(); String uid = config.getInitParameter("UID"); String pwd = config.getInitParameter("PWD"); String port = context.getInitParameter("some-port"); out.println("Values retrieved for the init parameters are: "); out.println("URL: " + url); out.println("UID: " + uid); out.println("PWD: " + pwd); out.println("some-port: " + port); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); // Get the current session object, create one if necessary HttpSession session = req.getSession(); out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>"); out.println("<BODY><H1>Session Timer</H1>"); // Display the previous timeout out.println("The previous timeout was " + session.getMaxInactiveInterval()); out.println("<BR>"); // Set the new timeout session.setMaxInactiveInterval(2 * 60 * 60); // two hours // Display the new timeout out.println("The newly assigned timeout is " + session.getMaxInactiveInterval()); out.println("</BODY></HTML>"); }
From source file:com.google.android.gcm.demo.server.AlertsServlet.java
/** * Displays the existing messages and offer the option to send a new one. *//*from ww w. j av a 2s.co m*/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("application/json"); String limit = req.getParameter("limit"); String offset = req.getParameter("offset"); JSONArray alerts = Datastore.getAllAlerts(Integer.parseInt(offset), Integer.parseInt(limit)); PrintWriter out = resp.getWriter(); out.print(alerts); resp.setStatus(HttpServletResponse.SC_OK); }