當前位置: 首頁>>代碼示例>>Java>>正文


Java ServletOutputStream.println方法代碼示例

本文整理匯總了Java中javax.servlet.ServletOutputStream.println方法的典型用法代碼示例。如果您正苦於以下問題:Java ServletOutputStream.println方法的具體用法?Java ServletOutputStream.println怎麽用?Java ServletOutputStream.println使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.servlet.ServletOutputStream的用法示例。


在下文中一共展示了ServletOutputStream.println方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleError

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void handleError(final HttpServletRequest request, final HttpServletResponse response)
		throws IOException {
	// handle limit case, e.g. return status code 429 (Too Many Requests)
	// see http://tools.ietf.org/html/rfc6585#page-3
	final String text = "TOO_MANY_REQUESTS";
	response.reset();
	response.setStatus(429);
	response.setContentType("text/plain");
	response.setCharacterEncoding("US-ASCII");
	response.setContentLength(text.length() + 2);
	response.setHeader("Pragma", "no-cache");
	response.setHeader("Cache-Control", "private, no-cache, no-store, must-revalidate");
	final ServletOutputStream out = response.getOutputStream();
	out.println(text);
	out.flush();
	response.flushBuffer();
}
 
開發者ID:ggrandes,項目名稱:concurrentlimit-servlet-filter,代碼行數:18,代碼來源:ConcurrentLimitFilter.java

示例2: viewXml

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void viewXml(RenderContext info, HttpServletResponse response) throws IOException
{
	response.setContentType("text/xml");
	ServletOutputStream outputStream = response.getOutputStream();
	outputStream.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
	outputStream.println(itemXsltService.getXmlForXslt(info, AbstractParentViewItemSection.getItemInfo(info))
		.toString());
	outputStream.flush();
	outputStream.close();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:11,代碼來源:DirListViewer.java

示例3: launchBasicLTI

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
    * Submit reflection form input database.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws Exception
    */
   private ActionForward launchBasicLTI(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException {
String mode = request.getParameter(AttributeNames.ATTR_MODE);
String sessionMapID = WebUtil.readStrParam(request, CommonCartridgeConstants.ATTR_SESSION_MAP_ID);
SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID);
CommonCartridgeItem item = getCommonCartridgeItem(request, sessionMap, mode);

ICommonCartridgeService service = getCommonCartridgeService();
WebApplicationContext wac = WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServlet().getServletContext());
MessageService messageService = (MessageService) wac.getBean("commonCartridgeMessageService");

// Get the post data for the placement
String returnValues = LamsBasicLTIUtil.postLaunchHTML(service, messageService, item);

try {
    response.setContentType("text/html; charset=UTF-8");
    response.setCharacterEncoding("utf-8");
    response.addDateHeader("Expires", System.currentTimeMillis() - (1000L * 60L * 60L * 24L * 365L));
    response.addDateHeader("Last-Modified", System.currentTimeMillis());
    response.addHeader("Cache-Control",
	    "no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0");
    response.addHeader("Pragma", "no-cache");
    ServletOutputStream out = response.getOutputStream();

    out.println("<!DOCTYPE html>");
    out.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">");
    out.println("<html>\n<head>");
    out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />");
    out.println("</head>\n<body>");
    out.println(returnValues);
    out.println("</body>\n</html>");

} catch (IOException e) {
    e.printStackTrace();
    throw e;
}

return null;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:51,代碼來源:ViewItemAction.java

示例4: doRenderOutput

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
public void doRenderOutput(HttpServletResponse res)
{
	res.setContentType("text/html");
	try
	{
		Document xmlOutput = m_tagDisplayOutput.getEmbeddedDocument() ;
		m_tagDisplayOutput.exportToFile(m_Config.getRootPath()+"output.xml") ;
		
		ServletOutputStream out = res.getOutputStream();
		if (xmlOutput == null)
		{
			res.setStatus(500);
			out.println("Session aborded") ;
		}
		else
		{
			ResourceManager man = m_Config.getResourceManager() ;
			XSLTransformer trans = man.getXSLTransformer("MAIN") ;
			if (trans == null)
			{
				out.println("Erreur interne") ;
				res.setStatus(500);
			}
			
			if (!trans.doTransform(xmlOutput, out))
			{
				out.println("Erreur interne") ;
				res.setStatus(500);
			}
			
		}
	}
	catch (IOException e)
	{
		res.setStatus(500);
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:38,代碼來源:DisplayOutput.java

示例5: doRenderOutput

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void doRenderOutput(Document xmlOutput, HttpServletResponse res, XSLTransformer trans)
{
	res.setContentType("text/html");
	try
	{
		ServletOutputStream out = res.getOutputStream();
		if (xmlOutput == null)
		{
			res.setStatus(500);
			out.println("Session aborded") ;
		}
		else
		{
			if (trans == null)
			{
				out.println("Erreur interne") ;
				res.setStatus(500);
			}
			
			if (!trans.doTransform(xmlOutput, out))
			{
				out.println("Erreur interne") ;
				out.close() ;
				res.setStatus(500);
			}
		}
		out.close();
	}
	catch (IOException e)
	{
		res.setStatus(500);
	}
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:34,代碼來源:XSLTServlet.java

示例6: renderOutput

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
private void renderOutput(Document xmlOutput, HttpServletResponse res, OnlineResourceManager resMan)
{
	XSLTransformer trans = resMan.getXSLTransformer() ;
	res.setContentType("text/html");
	try
	{
		ServletOutputStream out = res.getOutputStream();
		if (xmlOutput == null)
		{
			res.setStatus(500);
			out.println("Session aborded") ;
		}
		else
		{
			if (trans == null)
			{
				out.println("Erreur interne") ;
				res.setStatus(500);
			}
			else if (!trans.doTransform(xmlOutput, out))
			{
				out.println("Erreur interne") ;
				res.setStatus(500);
			}
		}
	}
	catch (IOException e)
	{
		res.setStatus(500);
	}		
}
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:32,代碼來源:ActionShowScreen.java

示例7: testLongProcess

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Verify that the test result can be returned correctly even when the
 * logic in the method to test takes a long time and thus it verifies that
 * the test result is only returned after it has been written in the
 * application scope on the server side.
 */
public void testLongProcess() throws Exception
{
    ServletOutputStream os = response.getOutputStream();
    os.print("<html><head><Long Process></head><body>");
    os.flush();

    // do some processing that takes a while ...
    Thread.sleep(3000);
    os.println("Some data</body></html>");
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:17,代碼來源:TestServletTestCase_TestResult.java

示例8: testLotsOfData

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Verify that when big amount of data is returned by the servlet output
 * stream, it does not io-block.
 */
public void testLotsOfData() throws Exception
{
    ServletOutputStream os = response.getOutputStream();
    os.println("<html><head>Lots of Data</head><body>");
    os.flush();
    for (int i = 0; i < 5000; i++) {
        os.println("<p>Lots and lots of data here");
    }
    os.println("</body></html>");
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:15,代碼來源:TestServletTestCase_TestResult.java

示例9: doGet

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    ServletOutputStream out = response.getOutputStream();
    response.setContentType("text/plain");

    Enumeration<String> e = request.getHeaders("Accept-Encoding");
    while (e.hasMoreElements()) {
        String name = e.nextElement();
        out.println(name);
        if (name.indexOf("gzip") != -1) {
            out.println("gzip supported -- able to compress");
        }
        else {
            out.println("gzip not supported");
        }
    }


    out.println("Compression Filter Test Servlet");
    out.println("Minimum content length for compression is 128 bytes");
    out.println("**********  32 bytes  **********");
    out.println("**********  32 bytes  **********");
    out.println("**********  32 bytes  **********");
    out.println("**********  32 bytes  **********");
    out.close();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:29,代碼來源:CompressionFilterTestServlet.java

示例10: outputHeader

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Output the header bytes for a multi-part byte range header
 */
void outputHeader(ServletOutputStream os) throws IOException
{
   // output multi-part boundry separator
   os.println(MULTIPART_BYTERANGES_BOUNDRY_SEP);
   // output content type and range size sub-header for this part
   os.println(this.contentType);
   os.println(getContentRange());
   os.println();
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:13,代碼來源:HttpRangeProcessor.java

示例11: doGet

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Provides CGI Gateway service
 *
 * @param  req   HttpServletRequest passed in by servlet container
 * @param  res   HttpServletResponse passed in by servlet container
 *
 * @exception  ServletException  if a servlet-specific exception occurs
 * @exception  IOException  if a read/write exception occurs
 *
 * @see javax.servlet.http.HttpServlet
 *
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    // Verify that we were not accessed using the invoker servlet
    if (req.getAttribute(Globals.INVOKED_ATTR) != null)
        throw new UnavailableException
            ("Cannot invoke CGIServlet through the invoker");

    CGIEnvironment cgiEnv = new CGIEnvironment(req, getServletContext());

    if (cgiEnv.isValid()) {
        CGIRunner cgi = new CGIRunner(cgiEnv.getCommand(),
                                      cgiEnv.getEnvironment(),
                                      cgiEnv.getWorkingDirectory(),
                                      cgiEnv.getParameters());
        //if POST, we need to cgi.setInput
        //REMIND: how does this interact with Servlet API 2.3's Filters?!
        if ("POST".equals(req.getMethod())) {
            cgi.setInput(req.getInputStream());
        }
        cgi.setResponse(res);
        cgi.run();
    }

    if (!cgiEnv.isValid()) {
        res.setStatus(404);
    }
 
    if (debug >= 10) {

        ServletOutputStream out = res.getOutputStream();
        out.println("<HTML><HEAD><TITLE>$Name$</TITLE></HEAD>");
        out.println("<BODY>$Header$<p>");

        if (cgiEnv.isValid()) {
            out.println(cgiEnv.toString());
        } else {
            out.println("<H3>");
            out.println("CGI script not found or not specified.");
            out.println("</H3>");
            out.println("<H4>");
            out.println("Check the <b>HttpServletRequest ");
            out.println("<a href=\"#pathInfo\">pathInfo</a></b> ");
            out.println("property to see if it is what you meant ");
            out.println("it to be.  You must specify an existant ");
            out.println("and executable file as part of the ");
            out.println("path-info.");
            out.println("</H4>");
            out.println("<H4>");
            out.println("For a good discussion of how CGI scripts ");
            out.println("work and what their environment variables ");
            out.println("mean, please visit the <a ");
            out.println("href=\"http://cgi-spec.golux.com\">CGI ");
            out.println("Specification page</a>.");
            out.println("</H4>");

        }

        printServletEnvironment(out, req, res);

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

    }


}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:79,代碼來源:CGIServlet.java

示例12: copy

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param resourceInfo The ResourceInfo object
 * @param ostream The output stream to write to
 * @param ranges Enumeration of the ranges the client wanted to retrieve
 * @param contentType Content type of the resource
 * @exception IOException if an input/output error occurs
 */
protected void copy(CacheEntry cacheEntry, ServletOutputStream ostream,
                  Iterator<Range> ranges, String contentType)
    throws IOException {

    IOException exception = null;

    while ( (exception == null) && (ranges.hasNext()) ) {

        InputStream resourceInputStream = cacheEntry.resource.streamContent();
        InputStream istream =
            new BufferedInputStream(resourceInputStream, input);

        Range currentRange = ranges.next();

        // Writing MIME header.
        ostream.println();
        ostream.println("--" + mimeSeparation);
        if (contentType != null)
            ostream.println("Content-Type: " + contentType);
        ostream.println("Content-Range: bytes " + currentRange.start
                       + "-" + currentRange.end + "/"
                       + currentRange.length);
        ostream.println();

        // Printing content
        exception = copyRange(istream, ostream, currentRange.start,
                              currentRange.end);

        istream.close();

    }

    ostream.println();
    ostream.print("--" + mimeSeparation + "--");

    // Rethrow any exception that has occurred
    if (exception != null)
        throw exception;

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:52,代碼來源:DefaultServlet.java

示例13: doGet

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Provides CGI Gateway service
 *
 * @param  req   HttpServletRequest passed in by servlet container
 * @param  res   HttpServletResponse passed in by servlet container
 *
 * @exception  ServletException  if a servlet-specific exception occurs
 * @exception  IOException  if a read/write exception occurs
 *
 * @see javax.servlet.http.HttpServlet
 *
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    // Verify that we were not accessed using the invoker servlet
    if (req.getAttribute(Globals.INVOKED_ATTR) != null)
        throw new UnavailableException
            ("Cannot invoke CGIServlet through the invoker");

    CGIEnvironment cgiEnv = new CGIEnvironment(req, getServletContext());

    if (cgiEnv.isValid()) {
        CGIRunner cgi = new CGIRunner(cgiEnv.getCommand(),
                                      cgiEnv.getEnvironment(),
                                      cgiEnv.getWorkingDirectory(),
                                      cgiEnv.getParameters());
        //if POST, we need to cgi.setInput
        //REMIND: how does this interact with Servlet API 2.3's Filters?!
        if ("POST".equals(req.getMethod())) {
            cgi.setInput(req.getInputStream());
        }
        cgi.setResponse(res);
        cgi.run();
    }


    //REMIND: change to debug method or something
    if ((req.getParameter("X_TOMCAT_CGI_DEBUG") != null)
        || (!cgiEnv.isValid())) {
        try {
            ServletOutputStream out = res.getOutputStream();
            out.println("<HTML><HEAD><TITLE>$Name:  $</TITLE></HEAD>");
            out.println("<BODY>$Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/servlets/CGIServlet.java,v 1.9 2002/09/05 21:46:54 amyroh Exp $<p>");

            if (cgiEnv.isValid()) {
                out.println(cgiEnv.toString());
            } else {
                res.setStatus(404);
                out.println("<H3>");
                out.println("CGI script not found or not specified.");
                out.println("</H3>");
                out.println("<H4>");
                out.println("Check the <b>HttpServletRequest ");
                out.println("<a href=\"#pathInfo\">pathInfo</a></b> ");
                out.println("property to see if it is what you meant ");
                out.println("it to be.  You must specify an existant ");
                out.println("and executable file as part of the ");
                out.println("path-info.");
                out.println("</H4>");
                out.println("<H4>");
                out.println("For a good discussion of how CGI scripts ");
                out.println("work and what their environment variables ");
                out.println("mean, please visit the <a ");
                out.println("href=\"http://cgi-spec.golux.com\">CGI ");
                out.println("Specification page</a>.");
                out.println("</H4>");

            }

            printServletEnvironment(out, req, res);

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

        } catch (IOException ignored) {
        }

    } //debugging


}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:82,代碼來源:CGIServlet.java

示例14: copy

import javax.servlet.ServletOutputStream; //導入方法依賴的package包/類
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param resourceInfo The ResourceInfo object
 * @param ostream The output stream to write to
 * @param ranges Enumeration of the ranges the client wanted to retrieve
 * @param contentType Content type of the resource
 * @exception IOException if an input/output error occurs
 */
private void copy(ResourceInfo resourceInfo, ServletOutputStream ostream,
                  Enumeration ranges, String contentType)
    throws IOException {

    IOException exception = null;

    while ( (exception == null) && (ranges.hasMoreElements()) ) {

        InputStream resourceInputStream = resourceInfo.getStream();
        InputStream istream =       // FIXME: internationalization???????
            new BufferedInputStream(resourceInputStream, input);

        Range currentRange = (Range) ranges.nextElement();

        // Writing MIME header.
        ostream.println("--" + mimeSeparation);
        if (contentType != null)
            ostream.println("Content-Type: " + contentType);
        ostream.println("Content-Range: bytes " + currentRange.start
                       + "-" + currentRange.end + "/"
                       + currentRange.length);
        ostream.println();

        // Printing content
        exception = copyRange(istream, ostream, currentRange.start,
                              currentRange.end);

        try {
            istream.close();
        } catch (Throwable t) {
            ;
        }

    }

    ostream.print("--" + mimeSeparation + "--");

    // Rethrow any exception that has occurred
    if (exception != null)
        throw exception;

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:54,代碼來源:DefaultServlet.java


注:本文中的javax.servlet.ServletOutputStream.println方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。