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:de.highbyte_le.weberknecht.request.view.JsonActionProcessor.java

public boolean processView(HttpServletRequest request, HttpServletResponse response, JsonView action)
        throws IOException, JSONException {

    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");

    BufferedWriter writer = null;
    try {//w  w w.ja v  a  2  s .  c  o  m
        writer = new BufferedWriter(response.getWriter());
        JSONWriter jsonWriter = new JSONWriter(writer);
        action.writeJson(jsonWriter);
        writer.flush();
    } finally {
        if (writer != null)
            writer.close();
    }

    return true;
}

From source file:net.sourceforge.subsonic.controller.M3UController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    response.setContentType("audio/x-mpegurl");
    response.setCharacterEncoding(StringUtil.ENCODING_UTF8);

    Player player = playerService.getPlayer(request, response);

    String url = request.getRequestURL().toString();
    url = url.replaceFirst("play.m3u.*", "stream?");

    // Rewrite URLs in case we're behind a proxy.
    if (settingsService.isRewriteUrlEnabled()) {
        String referer = request.getHeader("referer");
        url = StringUtil.rewriteUrl(url, referer);
    }//from   w ww . j av a2 s .  c om

    url = settingsService.rewriteRemoteUrl(url);

    if (player.isExternalWithPlaylist()) {
        createClientSidePlaylist(response.getWriter(), player, url);
    } else {
        createServerSidePlaylist(response.getWriter(), player, url);
    }
    return null;
}

From source file:org.easyj.rest.view.EasyView.java

protected void setUpResponse(HttpServletResponse response) {
    response.setContentType(getContentType());
    response.setCharacterEncoding(getEncoding());
    if (isPreventCache()) {
        responsePreventCache(response);/*from  ww  w.j  a va 2 s . c  o  m*/
    }
}

From source file:io.github.chibat.selva.response.JsonResponse.java

public void execute(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
        throws Exception {

    response.setStatus(this.status());
    response.setContentType(this.type());
    new ObjectMapper().writeValue(response.getWriter(), model);
    response.flushBuffer();//  www  . j  av a  2s. c o  m
}

From source file:com.happyuno.controller.EventController.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *///ww w.ja v a  2s  .  c om
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    request.setCharacterEncoding("utf-8");
    response.setHeader("Cache-Control", "no-cache");

    int playerId = Integer.parseInt(request.getParameter("playerId").trim());
    int gameId = Integer.parseInt(request.getParameter("tableId").trim());

    ServletContext application = request.getSession().getServletContext();
    HashMap<Integer, GameTable> gameTableMap = (HashMap<Integer, GameTable>) application
            .getAttribute("gameTableMap");
    //?
    Game game = gameTableMap.get(gameId).getCurrentGame();

    ArrayList<JSONObject> eventsAL = game.getEventCenter().getEvents(game.getPlayerFromId(playerId));

    JSONArray events = new JSONArray();
    for (int i = 0; i < eventsAL.size(); ++i) {
        events.put(eventsAL.get(i));
    }

    response.getWriter().write(events.toString());
}

From source file:com.healthcit.analytics.servlet.DataExportServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType(Constants.PLAIN_TEXT);
    resp.addHeader(Constants.PRAGMA_HEADER, Constants.NO_CACHE);
    resp.setHeader(Constants.CACHE_CONTROL_HEADER, Constants.NO_CACHE);
    String token = req.getParameter("token");
    PrintWriter writer = resp.getWriter();
    try {//from w w  w  .  j av  a2  s  . c  om
        if (token != null) {
            DownloadStatus status = TOKENS_MAP.get(token);
            if (status != null) {
                writer.print(status.name());
                if (DownloadStatus.FINISHED.equals(status)) {
                    TOKENS_MAP.remove(token);
                }
            } else {
                writer.print(DownloadStatus.ERROR.name());
            }
        } else {
            writer.print(DownloadStatus.ERROR.name());
        }
    } finally {
        writer.close();
    }
}

From source file:com.mykarsol.appconnectivity.imageload.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w w  w.  j  ava 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");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */

    }
}

From source file:com.student.manager.servlet.RegistrationServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from ww w.  j a  va  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");
    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 StudentRegistration</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet StudentRegistration at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

From source file:org.sample.nonblocking.WriteTestServlet.java

/**
 * Processes requests for both HTTP//from w w  w. j a v  a2s. c  o m
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @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()) {
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet WriteServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet WriteServlet at " + request.getContextPath() + "</h1>");

        AsyncContext context = request.startAsync();
        ServletOutputStream output = response.getOutputStream();
        output.setWriteListener(new MyWriteListener(output, context));

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:com.Accenture.Java.NewServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w  w  w  . j a  v 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");
    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 NewServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}