Example usage for javax.servlet ServletOutputStream println

List of usage examples for javax.servlet ServletOutputStream println

Introduction

In this page you can find the example usage for javax.servlet ServletOutputStream println.

Prototype


public void println(double d) throws IOException 

Source Link

Document

Writes a double value to the client, followed by a carriage return-line feed (CRLF).

Usage

From source file:org.apache.jena.fuseki.servlets.ResponseJson.java

private static void jsonOutput(HttpAction action, final Iterator<JsonObject> jsonItems) {
    OutputContent proc = new OutputContent() {
        @Override//from ww w  . j av a 2  s .  c  om
        public void output(ServletOutputStream out) {
            if (jsonItems != null)
                ResultSetFormatter.output(out, jsonItems);
        }
    };

    try {
        String callback = ResponseOps.paramCallback(action.request);
        ServletOutputStream out = action.response.getOutputStream();

        if (callback != null) {
            callback = StringUtils.replaceChars(callback, "\r", "");
            callback = StringUtils.replaceChars(callback, "\n", "");
            out.print(callback);
            out.println("(");
        }

        output(action, "application/json", WebContent.charsetUTF8, proc);

        if (callback != null)
            out.println(")");
    } catch (IOException ex) {
        ServletOps.errorOccurred(ex);
    }
}

From source file:org.apache.jena.fuseki.servlets.ResponseResultSet.java

private static void jsonOutput(HttpAction action, String contentType, final ResultSet resultSet,
        final Boolean booleanResult) {
    OutputContent proc = new OutputContent() {
        @Override/*from   www.  ja  v  a  2  s.co m*/
        public void output(ServletOutputStream out) {
            if (resultSet != null)
                ResultSetFormatter.outputAsJSON(out, resultSet);
            if (booleanResult != null)
                ResultSetFormatter.outputAsJSON(out, booleanResult);
        }
    };

    try {
        String callback = ResponseOps.paramCallback(action.request);
        ServletOutputStream out = action.response.getOutputStream();

        if (callback != null) {
            callback = StringUtils.replaceChars(callback, "\r", "");
            callback = StringUtils.replaceChars(callback, "\n", "");
            out.print(callback);
            out.println("(");
        }

        output(action, contentType, WebContent.charsetUTF8, proc);

        if (callback != null)
            out.println(")");
    } catch (IOException ex) {
        errorOccurred(ex);
    }
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    ServletOutputStream out = res.getOutputStream();
    res.setContentType("text/html");
    out.println("<html><head><title>Basic Servlet</title></head>");
    out.println("<body>Database username is  <b>" + dbName);
    out.println("</b><br>Database password is  <b>" + dbPassword + "</b>");
    out.println("</body></html>");
}

From source file:DeliberateException.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    ServletOutputStream out = res.getOutputStream();
    res.setContentType("text/html");
    out.println("<html><head><title>Exception Thrower</title></head>");
    out.println("<body>You'll never see this!</body></html>");

}

From source file:MyServlet.java

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
    ServletOutputStream out = res.getOutputStream();
    res.setContentType("text/html");
    out.println("<html><head><title>Basic Form Processor Output</title></head>");
    out.println("<body>");
    out.println("<h1>Here is your Form Data</h1>");
    //extract the form data here
    String title = req.getParameter("title");
    String name = req.getParameter("name");
    String city = req.getParameter("city");
    String country = req.getParameter("country");
    String tel = req.getParameter("tel");
    String age = req.getParameter("age");
    // extracting data from the checkbox field
    String[] interests = req.getParameterValues("interests");
    //output the data into a web page
    out.println("Your title is " + title);
    out.println("<br>Your name is " + name);
    out.println("<br>Your city is " + city);
    out.println("<br>Your country is " + country);
    out.println("<br>Your tel is " + tel);
    out.println("<br>Your interests include<ul> ");
    for (int i = 0; i < interests.length; i++) {
        out.println("<li>" + interests[i]);
    }//from  www. j  av  a 2 s. c  om
    out.println("</ul>");
    out.println("<br>Your age is " + age);
    out.println("</body></html>");
}

From source file:ShowFile.java

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

    ServletOutputStream out = response.getOutputStream();
    String fileName = request.getParameter("file");

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Welcome</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h2>The File</h2>");
    out.println(fileName);/* ww  w.  j  a v  a  2  s .  c  o m*/
    out.println("</body>");
    out.println("</html>");
    out.close();

}

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

private void doNoModelInContext(HttpServletRequest request, HttpServletResponse res) {
    try {//from w w w .  j a v  a  2  s. c  om
        res.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        ServletOutputStream sos = res.getOutputStream();
        sos.println("<html><body>this service is not supporeted by the current "
                + "webapp configuration. A jena model is required in the servlet context.</body></html>");
    } catch (IOException e) {
        log.error("Could not write to ServletOutputStream");
    }
}

From source file:LoggingServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    ServletOutputStream out = res.getOutputStream();
    context.log("doGet has now been invoked");
    res.setContentType("text/html");
    out.println("<html><head><title>Logging Servlet</title></head>");
    out.println("<body>Visit the <tomcat-home>\\logs and open the xx file to see the log entries");
    out.println("</body></html>");
}

From source file:DeleteBlobFromServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Connection conn = null;/* w w  w. j  ava2 s . c  om*/
    PreparedStatement pstmt = null;
    String id = "0001";
    ServletOutputStream out = response.getOutputStream();
    response.setContentType("text/html");
    out.println("<html><head><title>Delete Photo</title></head>");

    try {
        conn = getHSQLConnection();
        pstmt = conn.prepareStatement("delete from MyPictures where id = ?");
        pstmt.setString(1, id);
        pstmt.executeUpdate();
        out.println("<body><h3>deleted photo with id=" + id + "</h3></body></html>");
    } catch (Exception e) {
        out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>");
    } finally {
        try {
            pstmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:UpdateMySqlClobServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    Connection conn = null;/*from   w  ww .  j  av  a 2s.c o m*/
    String id = "001";
    String fileAsURL = "http://yourwebsite/fileName.dat";
    ServletOutputStream out = response.getOutputStream();
    response.setContentType("text/html");
    out.println("<html><head><title>UpdateMySqlClobServlet</title></head>");

    try {
        conn = getConnection();
        String fileContent = getClobsContentAsString(fileAsURL);
        updateCLOB(conn, id, fileContent);
        out.println("<body><h4>OK: updated an existing record with id=" + id + "</h4></body></html>");
    } catch (Exception e) {
        e.printStackTrace();
        out.println("<body><h4>Error: " + e.getMessage() + "</h4></body></html>");
    }
}