Example usage for javax.servlet.http HttpServletResponse setContentType

List of usage examples for javax.servlet.http HttpServletResponse setContentType

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse setContentType.

Prototype


public void setContentType(String type);

Source Link

Document

Sets the content type of the response being sent to the client, if the response has not been committed yet.

Usage

From source file:com.hp.autonomy.frontend.find.core.view.ViewController.java

@RequestMapping(value = VIEW_STATIC_CONTENT_PROMOTION_PATH, method = RequestMethod.GET)
public void viewStaticContentPromotion(@RequestParam(REFERENCE_PARAM) final String reference,
        final HttpServletResponse response) throws IOException, E {
    response.setContentType(MediaType.TEXT_HTML_VALUE);
    ViewContentSecurityPolicy.addContentSecurityPolicy(response);

    viewServerService.viewStaticContentPromotion(reference, response.getOutputStream());
}

From source file:com.nominanuda.springmvc.HttpEntityView.java

public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    response.setContentType(getContentType());
    InputStream is = entity.getContent();
    byte[] b = io.readAndClose(is);
    response.setContentLength(b.length);
    response.getOutputStream().write(b);
}

From source file:it.cilea.osd.jdyna.web.controller.AutocompleteUsersView.java

protected void renderMergedOutputModel(Map model, HttpServletRequest httpServletRequest,
        HttpServletResponse response) throws Exception {

    response.setContentType("text/xml");
    response.setHeader("Cache-Control", "no-cache");

    List<DTOAutocomplete> users = (List<DTOAutocomplete>) model.get("result");

    String xml = new AjaxXmlBuilder().addItems(users, "display", "id", true).toString();

    ServletOutputStream out = response.getOutputStream();
    out.print(xml);/*from   ww w .  ja v  a  2  s . co m*/
    out.close();

}

From source file:ru.mystamps.web.controller.RobotsTxtController.java

@GetMapping(Url.ROBOTS_TXT)
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public void getRobotsText(HttpServletResponse response) {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");

    try {//  w w  w.  j a v a  2  s  .  co  m
        PrintWriter writer = response.getWriter();

        writer.println("# robots.txt for " + Url.PUBLIC_URL);
        writer.println("User-Agent: *");
        writer.println("Disallow: " + Url.REGISTRATION_PAGE);
        writer.println("Disallow: " + Url.ACTIVATE_ACCOUNT_PAGE);
        writer.println("Disallow: " + Url.AUTHENTICATION_PAGE);
        writer.println("Disallow: " + Url.LOGIN_PAGE);
        writer.println("Disallow: " + Url.ADD_COUNTRY_PAGE);
        writer.println("Disallow: " + Url.ADD_SERIES_PAGE);
        writer.println("Disallow: " + Url.ADD_CATEGORY_PAGE);
        writer.println("Disallow: " + Url.FORBIDDEN_PAGE);
        writer.println("Disallow: " + Url.NOT_FOUND_PAGE);
        writer.println("Disallow: " + Url.INTERNAL_ERROR_PAGE);
        writer.println("Sitemap: " + Url.PUBLIC_URL + Url.SITEMAP_XML);
    } catch (IOException ex) {
        LOG.error("Can't return robots.txt: {}", ex.getMessage());
    }
}

From source file:com.asual.summer.xml.XmlView.java

protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    response.setContentType(getContentType());
    response.setCharacterEncoding(request.getCharacterEncoding());

    XmlMapper mapper = new XmlMapper();
    mapper.configure(Feature.AUTO_CLOSE_TARGET, false);
    mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
    mapper.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    mapper.writeValue(response.getOutputStream(), filterModel(model));
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    String remoteUser = req.getRemoteUser();

    if (remoteUser == null) {
        out.println("Welcome!");
    } else {/*from w ww.j  a v  a2 s  .  c  om*/
        out.println("Welcome, " + remoteUser + "!");
        Date lastAccess = (Date) accesses.get(remoteUser);
        if (lastAccess == null) {
            out.println("This is your first visit!");
        } else {
            out.println("Your last visit was " + accesses.get(remoteUser));
        }

        if (remoteUser.equals("YourFirendName")) {
            out.println("Shall we play a game?");
        }

        accesses.put(remoteUser, new Date());
    }
}

From source file:com.hp.autonomy.frontend.find.core.view.ViewController.java

@RequestMapping(value = VIEW_DOCUMENT_PATH, method = RequestMethod.GET)
public void viewDocument(@RequestParam(REFERENCE_PARAM) final String reference,
        @RequestParam(DATABASE_PARAM) final S database,
        @RequestParam(value = HIGHLIGHT_PARAM, required = false) final String highlightExpression,
        final HttpServletResponse response) throws E, IOException {
    response.setContentType(MediaType.TEXT_HTML_VALUE);
    ViewContentSecurityPolicy.addContentSecurityPolicy(response);
    viewServerService.viewDocument(reference, database, highlightExpression, response.getOutputStream());
}

From source file:PersonalizedServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    String remoteUser = req.getRemoteUser();

    if (remoteUser == null) {
        out.println("Welcome!");
    } else {/*from   w ww .  ja  v  a2s . co  m*/
        out.println("Welcome, " + remoteUser + "!");
        Date lastAccess = (Date) accesses.get(remoteUser);
        if (lastAccess == null) {
            out.println("This is your first visit!");
        } else {
            out.println("Your last visit was " + accesses.get(remoteUser));
        }
        if (remoteUser.equals("User A")) {
            out.println("HI.");
        }
        accesses.put(remoteUser, new Date());
    }

}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    HttpSession session = req.getSession();

    Integer count = (Integer) session.getAttribute("tracker.count");
    if (count == null)
        count = new Integer(1);
    else//from  w w  w .  j a va  2s . co  m
        count = new Integer(count.intValue() + 1);
    session.setAttribute("tracker.count", count);

    out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
    out.println("<BODY><H1>Session Tracking Demo</H1>");

    out.println("You've visited this page " + count + ((count.intValue() == 1) ? " time." : " times."));

    out.println("<P>");

    out.println("<H2>Here is your session data:</H2>");
    Enumeration e = session.getAttributeNames();
    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println(name + ": " + session.getAttribute(name) + "<BR>");
    }
    out.println("</BODY></HTML>");
}

From source file:de.science.hack.jetstream.web.controller.DownloadController.java

private OutputStream prepareResponse(HttpServletResponse response) throws IOException {
    response.setContentType(MIME);
    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"", GLOBE);
    response.setHeader(headerKey, headerValue);
    return response.getOutputStream();
}