List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:io.hawt.testing.env.builtin.EmptyJolokiaEnvironment.java
@Override public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("application/json"); resp.setCharacterEncoding("UTF-8"); if (req.getPathInfo().equals("")) { resp.getWriter().print(handle(RequestType.VERSION).toJSONString()); }/*from ww w .j av a 2s . c o m*/ resp.getWriter().close(); }
From source file:EnvEntry.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); try {/* w w w .ja v a2 s . co m*/ Context initCtx = new InitialContext(); NamingEnumeration e = initCtx.listBindings("java:comp/env"); while (e.hasMore()) { Binding binding = (Binding) e.next(); out.println("Name: " + binding.getName()); out.println("Type: " + binding.getClassName()); out.println("Value: " + binding.getObject()); out.println(); } } catch (NamingException e) { e.printStackTrace(out); } }
From source file:br.eb.ime.pfc.domain.GeoServerCommunication.java
private static void redirectStream(String urlName, HttpServletRequest request, HttpServletResponse response) { URL url = null;/*from ww w. j a va 2 s .co m*/ try { url = new URL(urlName); } catch (MalformedURLException e) { //Internal error, the user will receive no data. sendError(HTTP_STATUS.BAD_REQUEST, response); return; } HttpURLConnection conn = null; try { conn = (HttpURLConnection) url.openConnection(); conn.addRequestProperty("Authorization", "Basic " + BASE64_AUTHORIZATION); //conn.setRequestMethod("GET"); //conn.setDoOutput(true); conn.connect(); } catch (IOException e) { sendError(HTTP_STATUS.INTERNAL_ERROR, response); return; } try (InputStream is = conn.getInputStream(); OutputStream os = response.getOutputStream()) { response.setContentType(conn.getContentType()); IOUtils.copy(is, os); } catch (IOException e) { request.getServletContext().log("IO"); sendError(HTTP_STATUS.INTERNAL_ERROR, response); return; } finally { //Close connection to save resources conn.disconnect(); } }
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(); Enumeration en = request.getParameterNames(); while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); out.println(paramName + " = " + request.getParameter(paramName) + "<br/>"); }//from w ww. j a v a 2 s . c o m }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain; charset=Shift_JIS"); PrintWriter out = res.getWriter(); res.setHeader("Content-Language", "ja"); Locale locale = new Locale("ja", ""); DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); out.println("In Japanese:"); try {/*from www. j a v a2 s . co m*/ FileInputStream fis = new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP")); InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP"); BufferedReader reader = new BufferedReader(isr); String line = null; while ((line = reader.readLine()) != null) { out.println(line); } } catch (FileNotFoundException e) { e.printStackTrace(); } out.println(full.format(new Date())); }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); if (lastprime == 0) { out.println("Still searching for first prime..."); } else {/*w w w .j a v a 2 s . c o m*/ out.println("The last prime discovered was " + lastprime); out.println(" at " + lastprimeModified); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("A Web Page"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("Hello there!"); out.println("</BODY>"); out.println("</HTML>"); }
From source file:ChartServlet.java
/** Draw a Graphical Chart in response to a user request */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("image/jpeg"); // Create an Image BufferedImage img = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); // Get the Image's Graphics, and draw. Graphics2D g = img.createGraphics(); // In real life this would call some charting software... g.setColor(Color.white);/*ww w . j a va 2 s .c om*/ g.fillRect(0, 0, W, H); g.setColor(Color.green); g.fillOval(100, 75, 50, 50); // Write the output OutputStream os = response.getOutputStream(); ImageOutputStream ios = ImageIO.createImageOutputStream(os); if (!ImageIO.write(img, "jpeg", ios)) { log("Boo hoo, failed to write JPEG"); } ios.close(); os.close(); }
From source file:de.iew.web.view.js.JavascriptConfigView.java
@Override protected void renderMergedOutputModel(Map<String, Object> stringObjectMap, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/javascript; charset=utf-8"); PrintWriter writer = response.getWriter(); writer.write("define(function(){return{"); writer.write(renderBaseUrlHelper(request)); writer.write("}});"); }
From source file:action.ChartResult.java
@Override public void execute(ActionInvocation invocation) throws Exception { ImageAction action = (ImageAction) invocation.getAction(); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); JFreeChart chart = action.getChart(); int width = 500; int height = 350; ChartUtilities.writeChartAsPNG(outputStream, chart, width, height); }