本文整理汇总了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();
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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>");
}
示例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>");
}
示例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();
}
示例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>");
}
}
示例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;
}
示例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
}
示例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;
}