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:LocaleInformationServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    Locale userPreferredLocale = request.getLocale();
    Enumeration userPreferredLocales = request.getLocales();

    out.println("Preferred Locale: " + userPreferredLocale.toString());
    out.println("");
    out.print("Preferred Locales: ");

    while (userPreferredLocales.hasMoreElements()) {
        userPreferredLocale = (Locale) userPreferredLocales.nextElement();
        out.print(userPreferredLocale.toString() + ", ");
    }// w  w  w . j  av a2s . com
    out.println();
    out.println("");
}

From source file:org.openmrs.module.logmanager.web.view.AutocompleteView.java

@SuppressWarnings("rawtypes")
@Override/* ww w. j  a  va  2s  . c  o m*/
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    PrintWriter writer = response.getWriter();
    Object source = model.get(sourceKey);

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");
    response.setContentType("application/json");

    writer.write("[");

    if (source != null) {
        if (source instanceof Collection) {
            Collection<?> collection = (Collection<?>) source;
            Object[] items = collection.toArray();
            for (int i = 0; i < items.length; i++) {
                Object item = items[i];
                String label = (item instanceof LoggerProxy) ? ((LoggerProxy) item).getName() : item.toString();

                if (i > 0)
                    writer.write(',');

                writer.write("{\"label\":\"" + label + "\", \"value\":\"" + label + "\"}");
            }
        }
    } else
        writer.write("\"ERROR: Source object is null\"");

    writer.write("]");
}

From source file:com.webtide.jetty.load.generator.web.UploadServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String answer = "GET does nothing";
    LOGGER.info(answer);//from  www.  j av  a  2  s. com
    resp.getWriter().print(answer);
}

From source file:eu.delving.services.controller.SearchApiController.java

@RequestMapping("/api/search")
public void searchApiController(HttpServletRequest request, Locale locale, HttpServletResponse response)
        throws Exception {
    response.setCharacterEncoding("UTF-8");
    response.getWriter()
            .write(richApiServiceFactory.getApiResponse(request, locale, ThemeFilter.getLookup(), response));
    response.getWriter().close();/*from   ww w  .  j a  v a  2  s.c  om*/
}

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

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setStatus(SC_FORBIDDEN);//from  www  .j  a  v a 2s  .  c  o m
    response.getWriter().write(exception.getMessage());

}

From source file:LoginHandler.java

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

    String account = req.getParameter("account");
    String password = req.getParameter("password");
    String pin = req.getParameter("pin");

    if (!allowUser(account, password, pin)) {
        out.println("<HTML><HEAD><TITLE>Access Denied</TITLE></HEAD>");
        out.println("<BODY>Your login and password are invalid.<BR>");
        out.println("You may want to <A HREF=\"/login.html\">try again</A>");
        out.println("</BODY></HTML>");
    } else {/*from w  w w  . j a v  a2 s. com*/
        // Valid login. Make a note in the session object.
        HttpSession session = req.getSession();
        session.setAttribute("logon.isDone", account);
        // Try redirecting the client to the page he first tried to access
        try {
            String target = (String) session.getAttribute("login.target");
            if (target != null) {
                res.sendRedirect(target);
                return;
            }
        } catch (Exception ignored) {
        }

        // Couldn't redirect to the target. Redirect to the site's home page.
        res.sendRedirect("/");
    }
}

From source file:com.seer.datacruncher.profiler.spring.CompareTableController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();
    String action = CommonUtil.notNullValue(request.getParameter("action"));
    CompareTableBL ctbl = new CompareTableBL();
    ctbl.setTable1(CommonUtil.notNullValue(request.getParameter("table1")));
    ctbl.setTable2(CommonUtil.notNullValue(request.getParameter("table2")));
    ctbl.setCol1(CommonUtil.notNullValue(request.getParameter("col1")));
    ctbl.setCol2(CommonUtil.notNullValue(request.getParameter("col2")));
    ctbl.setRb(CommonUtil.notNullValue(request.getParameter("relation")));
    ctbl.setFt(CommonUtil.notNullValue(request.getParameter("ft")));
    ctbl.setLink(CommonUtil.notNullValue(request.getParameter("link")));

    boolean editable = new Boolean(CommonUtil.notNullValue(request.getParameter("editable")));
    if (action.equals("link")) {
        TableGridDTO tgDTO = ctbl.linkClicked();
        GridUtil gridUtil = new GridUtil();
        gridUtil.generateGridData(tgDTO, editable, null);
        out.println("{\"success\": true, \"data\":" + gridUtil.getData() + ", \"columns\":"
                + gridUtil.getColumnNames() + ", \"fields\":" + gridUtil.getFieldNames() + "}");
    } else {/*from   w w  w  .j ava  2s.com*/
        Map<String, List<String>> dataMap = ctbl.buttonClicked();
        String data = ChartUtil.generateDataSetFromMap(dataMap);
        out.println("{\"success\": true, \"data\":" + data + "}");
    }

    return null;
}

From source file:MainClass.java

public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, java.io.IOException {

    res.setContentType("text/html");
    java.io.PrintWriter out = res.getWriter();
    out.println("<HTML>");
    out.println("<HEAD><TITLE>User Example</TITLE></HEAD>");
    out.println("<BODY>");

    String username = req.getRemoteUser();
    if (username == null) {
        out.println("Hello. You are not logged in.");
    } else if ("Bob".equals(username)) {
        out.println("Hello, Bob. Nice to see you again.");
    } else {/*from  w  w w. ja  v  a2  s.  co  m*/
        out.println("Hello, " + username + ".");
    }
    out.println("</BODY>");
    out.println("</HTML>");
    out.close();
}

From source file:com.job.portal.servlets.JobsServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    JSONObject obj = null;/*w  ww  . j av  a  2 s. c om*/
    JSONArray arr = null;
    try {
        String param = request.getParameter("param");
        JobsManager jm = new JobsManager();
        if (param != null) {
            if (param.equalsIgnoreCase("addJob")) {
                boolean flag = jm.addJob(request);
                obj = new JSONObject();
                obj.put("status", flag);
                if (flag) {
                    obj.put("msg", "Job created successfully");
                } else {
                    obj.put("msg", "Please try again after sometime");
                }
                out.print(obj);
            } else if (param.equalsIgnoreCase("getJobDetails")) {
                obj = jm.getJobDetails(request);
                out.print(obj);
            } else if (param.equalsIgnoreCase("getJobApplicants")) {
                arr = jm.getJobApplicants(request);
                out.print(arr);
            } else if (param.equalsIgnoreCase("showAll")) {
                arr = jm.getAllJobs(request);
                out.print(arr);
            }
        }
    } catch (Exception e) {
        LogOut.log.error("In " + new Object() {
        }.getClass().getEnclosingClass().getName() + "." + new Object() {
        }.getClass().getEnclosingMethod().getName() + " " + e);
    } finally {
        out.close();
    }
}

From source file:MainServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    count++;//from  w  w  w  . j a v a  2s. c  o m
    out.println("Since the beginning, this servlet has been accessed " + count + " times.");
}