当前位置: 首页>>代码示例>>Java>>正文


Java ServletOutputStream.print方法代码示例

本文整理汇总了Java中javax.servlet.ServletOutputStream.print方法的典型用法代码示例。如果您正苦于以下问题:Java ServletOutputStream.print方法的具体用法?Java ServletOutputStream.print怎么用?Java ServletOutputStream.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletOutputStream的用法示例。


在下文中一共展示了ServletOutputStream.print方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTrace

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Called by the server (via the <code>service</code> method)
 * to allow a servlet to handle a TRACE request.
 *
 * A TRACE returns the headers sent with the TRACE
 * request to the client, so that they can be used in
 * debugging. There's no need to override this method.
 *
 * @param req   the {@link HttpServletRequest} object that
 *                  contains the request the client made of
 *                  the servlet
 *
 * @param resp  the {@link HttpServletResponse} object that
 *                  contains the response the servlet returns
 *                  to the client
 *
 * @exception IOException   if an input or output error occurs
 *                              while the servlet is handling the
 *                              TRACE request
 *
 * @exception ServletException  if the request for the
 *                                  TRACE cannot be handled
 */
protected void doTrace(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
{

    int responseLength;

    String CRLF = "\r\n";
    StringBuilder buffer = new StringBuilder("TRACE ").append(req.getRequestURI())
        .append(" ").append(req.getProtocol());

    Enumeration<String> reqHeaderEnum = req.getHeaderNames();

    while( reqHeaderEnum.hasMoreElements() ) {
        String headerName = reqHeaderEnum.nextElement();
        buffer.append(CRLF).append(headerName).append(": ")
            .append(req.getHeader(headerName));
    }

    buffer.append(CRLF);

    responseLength = buffer.length();

    resp.setContentType("message/http");
    resp.setContentLength(responseLength);
    ServletOutputStream out = resp.getOutputStream();
    out.print(buffer.toString());
    out.close();
    return;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:53,代码来源:HttpServlet.java

示例2: onAuthenticationFailure

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
public void onAuthenticationFailure (HttpServletRequest request,
   HttpServletResponse response, AuthenticationException exception)
   throws IOException, ServletException
{
   response.setContentType ("text/plain");
   response.setStatus (HttpServletResponse.SC_UNAUTHORIZED);
   ServletOutputStream outputStream = response.getOutputStream ();
   outputStream.print (exception.getMessage ());
   outputStream.close ();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:12,代码来源:LoginFailureHandler.java

示例3: service

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
	final String path = req.getPathInfo();

	if( path.equals("/refresh") )
	{
		languageService.refreshBundles();

		resp.setContentType("text/plain");
		ServletOutputStream out = resp.getOutputStream();
		out.print("Bundles refreshed");
		out.close();
		return;
	}

	Matcher m = Pattern.compile("^/([a-zA-Z_]*)/([a-zA-Z-]+)\\.properties$").matcher(path);
	if( !m.matches() || m.groupCount() != 2 )
	{

		throw new ServletException("Bundle Group name is invalid: " + path);
	}

	final ResourceBundle resourceBundle = languageService.getResourceBundle(LocaleUtils.parseLocale(m.group(1)),
		m.group(2));

	final Properties text = new Properties();
	for( String key : resourceBundle.keySet() )
	{
		text.put(key, resourceBundle.getString(key));
	}

	resp.setContentType("text/plain");
	resp.setHeader("Content-Disposition", "inline; filename=" + path + ".properties");

	text.store(resp.getOutputStream(), null);
}
 
开发者ID:equella,项目名称:Equella,代码行数:38,代码来源:LanguageServlet.java

示例4: saveNewImage

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
    * Save file or url imageGallery item into database.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws IOException 
    */
   private ActionForward saveNewImage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException {
ImageGalleryItemForm itemForm = (ImageGalleryItemForm) form;
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(itemForm.getSessionMapID());
ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE);

//validate form
boolean isLargeFilesAllowed = mode.isTeacher();
ActionErrors errors = ImageGalleryUtils.validateImageGalleryItem(itemForm, isLargeFilesAllowed);

try {
    if (errors.isEmpty()) {
	extractFormToImageGalleryItem(request, itemForm);
    }
} catch (Exception e) {
    // any upload exception will display as normal error message rather then throw exception directly
    errors.add(ActionMessages.GLOBAL_MESSAGE,
	    new ActionMessage(ImageGalleryConstants.ERROR_MSG_UPLOAD_FAILED, e.getMessage()));
}

if (!errors.isEmpty()) {
    ServletOutputStream outputStream = response.getOutputStream();
    outputStream.print(errors.get().next().toString());
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:LearningAction.java

示例5: saveMultipleImages

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
    * Save file or url imageGallery item into database.
    *
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return
    * @throws IOException 
    */
   private ActionForward saveMultipleImages(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException {
MultipleImagesForm multipleForm = (MultipleImagesForm) form;
SessionMap<String, Object> sessionMap = (SessionMap<String, Object>) request.getSession().getAttribute(multipleForm.getSessionMapID());
ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE);

//validate form
boolean isLargeFilesAllowed = mode.isTeacher();
ActionErrors errors = ImageGalleryUtils.validateMultipleImages(multipleForm, isLargeFilesAllowed);

try {
    if (errors.isEmpty()) {
	extractMultipleFormToImageGalleryItems(request, multipleForm);
    }
} catch (Exception e) {
    // any upload exception will display as normal error message rather then throw exception directly
    errors.add(ActionMessages.GLOBAL_MESSAGE,
	    new ActionMessage(ImageGalleryConstants.ERROR_MSG_UPLOAD_FAILED, e.getMessage()));
}

if (!errors.isEmpty()) {
    ServletOutputStream outputStream = response.getOutputStream();
    outputStream.print(errors.get().next().toString());
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:LearningAction.java

示例6: 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

示例7: doGet

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String payload = String.format("{\"enabled\": %s}%n", getFilter().isEnabled());
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        outputStream.print(payload);
    } finally {
        outputStream.close();
    }
}
 
开发者ID:vy,项目名称:hrrs,代码行数:13,代码来源:HrrsServlet.java

示例8: doTrace

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Called by the server (via the <code>service</code> method) to allow a
 * servlet to handle a TRACE request.
 *
 * A TRACE returns the headers sent with the TRACE request to the client, so
 * that they can be used in debugging. There's no need to override this
 * method.
 *
 * @param req
 *            the {@link HttpServletRequest} object that contains the
 *            request the client made of the servlet
 *
 * @param resp
 *            the {@link HttpServletResponse} object that contains the
 *            response the servlet returns to the client
 *
 * @exception IOException
 *                if an input or output error occurs while the servlet is
 *                handling the TRACE request
 *
 * @exception ServletException
 *                if the request for the TRACE cannot be handled
 */
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	int responseLength;

	String CRLF = "\r\n";
	StringBuilder buffer = new StringBuilder("TRACE ").append(req.getRequestURI()).append(" ")
			.append(req.getProtocol());

	Enumeration<String> reqHeaderEnum = req.getHeaderNames();

	while (reqHeaderEnum.hasMoreElements()) {
		String headerName = reqHeaderEnum.nextElement();
		buffer.append(CRLF).append(headerName).append(": ").append(req.getHeader(headerName));
	}

	buffer.append(CRLF);

	responseLength = buffer.length();

	resp.setContentType("message/http");
	resp.setContentLength(responseLength);
	ServletOutputStream out = resp.getOutputStream();
	out.print(buffer.toString());
	out.close();
	return;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:50,代码来源:HttpServlet.java

示例9: 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

示例10: 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.print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。