Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

In this page you can find the example usage for java.io PrintWriter println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:org.jsnap.http.base.HttpReject.java

protected void doServiceImpl(HttpRequest request, HttpResponse response) {
    response.statusCode = HttpStatus.SC_SERVICE_UNAVAILABLE;
    response.contentType = Formatter.PLAIN;
    response.characterSet = Formatter.ISO_8859_1;
    PrintWriter writer = new PrintWriter(response.out);
    writer.println("Server is too busy to handle your request. Please retry at a later time.");
}

From source file:com.aurel.track.item.ItemDetailBL.java

public static void encodeTabJSON(String itemsJSON, boolean includeLayout, Integer tabID, Integer personID,
        Locale locale) {//w  w w .  ja  v  a  2s  .c  om
    String result;
    if (includeLayout) {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        JSONUtility.appendBooleanValue(sb, JSON_FIELDS.SUCCESS, true);
        JSONUtility.appendFieldName(sb, JSONUtility.JSON_FIELDS.DATA).append(":{");
        List<ItemGridLayout> layout = ItemGridLayoutBL.loadLayout(tabID, personID, null, locale);
        JSONUtility.appendFieldName(sb, "gridLayoutData").append(":{");
        JSONUtility.appendJSONValue(sb, "layout", ItemDetailBL.encodeJSON_Layout(layout, locale), true);
        sb.append("},");
        JSONUtility.appendJSONValue(sb, "items", itemsJSON, true);
        sb.append("}}");
        result = sb.toString();
    } else {
        result = itemsJSON;
    }
    try {
        JSONUtility.prepareServletResponseJSON(ServletActionContext.getResponse());
        PrintWriter out = ServletActionContext.getResponse().getWriter();
        out.println(result);
    } catch (IOException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:com.websqrd.catbot.setting.CatbotSettings.java

public static void saveIncInfo(String site, String category, String incInfo) {
    try {//  w w  w  .ja va2 s . c  o  m
        File f = new File(getSiteKey(site, category + "_" + incInfoFilename));
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f, false)));
        writer.println(incInfo);
        writer.close();
        logger.debug("Save {} / {}  pk >> {} ", new Object[] { site, category, incInfo });
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:$.SayHi.java

public void execute() throws Exception {
        // content type??charsetcharset
        response.setContentType("text/plain");

        // ?servlet??
        PrintWriter out = response.getWriter();

        out.println("Hi there, how are you doing today?");
    }//from   ww w  .  ja  v a  2s . c  o  m

From source file:MyServlet.java

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

    res.setHeader("Refresh", "10");
    out.println(new Date().toString());
}

From source file:MyServlet.java

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

    count++;/* w w w.j  ava2s  . c  o m*/
    out.println("Since loading, this servlet instance has been accessed " + count + " times.");

    // Keep track of the instance count by putting a reference to this
    // instance in a Hashtable. Duplicate entries are ignored.
    // The size() method returns the number of unique instances stored.
    instances.put(this, this);
    out.println("There are currently " + instances.size() + " instances.");

    classCount++;
    out.println("Across all instances, this servlet class has been " + "accessed " + classCount + " times.");
}

From source file:ro.allevo.fintpws.security.ApiAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("Access-Control-Allow-Origin", "null");
    response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.println(
            "Here : HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage());
}

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

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

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

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Include Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Welcome To Our Universe</h1>");
    out.println("Imagine the rest of the page here.<br><br>");
    //Include the copyright information
    RequestDispatcher dispatcher = request.getRequestDispatcher("/CopyRight");
    dispatcher.include(request, response);

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

    out.close();//ww  w .j  ava  2  s .c  om

}

From source file:MyServlet.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String password = ((HttpServletRequest) request).getParameter("password");

    if (password.equals("opensesame")) {
        chain.doFilter(request, response);
    } else {/*ww  w  .j  av  a  2 s . co  m*/
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<HEAD>");
        out.println("<TITLE>");
        out.println("Incorrect Password");
        out.println("</TITLE>");
        out.println("</HEAD>");
        out.println("<BODY>");
        out.println("<H1>Incorrect Password</H1>");
        out.println("Sorry, that password was incorrect.");
        out.println("</BODY>");
        out.println("</HTML>");
    }
}