Example usage for javax.servlet.http HttpServletResponse getWriter

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

Introduction

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

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:edu.cornell.mannlib.vitro.webapp.controller.api.VitroApiServlet.java

private PrintWriter getWriter(HttpServletResponse resp) throws IOException {
    try {/* ww  w . j a  v  a 2 s . c  o m*/
        return resp.getWriter();
    } catch (IllegalStateException e) {
        return new PrintWriter(new OutputStreamWriter(resp.getOutputStream()));
    }
}

From source file:net.hillsdon.reviki.web.pages.impl.TextFormatSearchResults.java

public void render(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    response.setContentType("text/plain");
    render(request, response.getWriter());
}

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("User Authentication");
    out.println("</TITLE>");
    out.println("</HEAD>");
    out.println("<BODY>");
    out.println("<H1>User Authentication</H1>");

    String type = request.getAuthType();
    out.println("Welcome to this secure page.<BR>");
    out.println("Authentication mechanism: " + type + "<BR>");
    Principal principal = request.getUserPrincipal();
    out.println("Your username is: " + principal.getName() + "<BR>");

    out.println("</BODY>");
    out.println("</HTML>");
}

From source file:com.dianping.cache.servlet.CacheMessageSenderServlet.java

/**
 * Get building message parameters, and then send this message to JMS
 * server./*from  ww  w  .  java2 s  . c o  m*/
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    try {
        String type = req.getParameter(MESSAGE_TYPE);
        String value = req.getParameter(MESSAGE_VALUE);

        if (!StringUtils.hasLength(type) || !StringUtils.hasLength(value)) {
            out.println(
                    "Cache message format should like this: http://host:port/cache-message/send.action?type=1&value=test");
        }
        int messageType = parseInt(type);
        if (Constants.KEYTYPE_VERSION_UPDATE_MESSAGE == messageType) {
            cacheManageService.clearByCategory(value);
        } else if (Constants.SINGLE_CACHE_REMOVE_MESSAGE == messageType) {
            cacheManageService.clearByKey("web", value);
            cacheManageService.clearByKey("memcached", value);
        }
        out.println("Send message successfully!");
    } finally {
        out.close();
    }
}

From source file:com.linuxbox.enkive.web.AbstractJsonServlet.java

protected void setResponse(HttpServletResponse response, JSONObject jsonObject) {
    String jsonResultString = jsonObject.toString();
    try {/*from  www .  j a v  a  2  s . c  o m*/
        response.getWriter().write(jsonResultString);
    } catch (IOException e) {
        LOGGER.error("Could not write webscript response");
    }
}

From source file:com.qwazr.webapps.exception.WebappException.java

private void sendQuietlyJSON(HttpServletResponse response) throws IOException {
    JsonMapper.MAPPER.writeValue(response.getWriter(), error);
}

From source file:controller.UpdateImage.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    HttpSession session = request.getSession();
    String manv = session.getAttribute("manv").toString();
    if (!ServletFileUpload.isMultipartContent(request)) {
        out.println("Nothing to upload");
        return;/*from  w  w w.  jav  a 2s  . c  om*/
    }
    FileItemFactory itemfactory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(itemfactory);
    String a = "";
    try {
        List<FileItem> items = upload.parseRequest(request);
        for (FileItem item : items) {
            String myfolder = ("asset/Images/nhanvien") + "/";
            File uploadDir = new File(
                    "E:/Cng ngh phn m?m/? ?n/1996Shop/ShopOnline/web/asset/Images/nhanvien");
            File file = File.createTempFile("img", ".png", uploadDir);
            item.write(file);
            a = myfolder + file.getName();
            nv.setImage(a);
            usersDAO.updateImage(a, manv);
            response.sendRedirect("Profile.jsp?MaNV=" + manv + "");
        }

    } catch (FileUploadException e) {
        out.println("upload fail");
    } catch (Exception ex) {

    }
}

From source file:org.chtijbug.drools.platform.web.security.Http200AuthenticationSuccessHandler.java

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().write(authentication.getName());
}

From source file:WebAppProperties.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();
    ServletContext context = getServletContext();
    String displayName = context.getServletContextName();
    if (displayName == null) {
        displayName = "(no display-name element defined)";
    }//  ww  w.  j  a v  a  2s  .  co  m

    out.println("<html>");
    out.println("<body>");
    out.println("<br>Name: " + displayName);
    out.println("<br>Context: " + req.getContextPath());

    out.println("<h2><center>");
    out.println("Initialization Parameters</center></h2>");
    out.println("<br>");

    out.println("<center><table>");

    Enumeration e = context.getInitParameterNames();

    while (e.hasMoreElements()) {
        String name = (String) e.nextElement();
        out.println("<tr>");
        out.println("<td>" + name + "</td>");
        out.println("<td>" + context.getInitParameter(name) + "</td>");
        out.println("</tr>");
    }
    out.println("</table></center>");

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

From source file:de.perdian.apps.dashboard.mvc.portal.PortalView.java

private void appendDashboardBody(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.getWriter().append("<script type=\"text/javascript\">\n");
    this.appendDashboardJsContent(model, request, response);
    response.getWriter().append("</script>\n");
}