Servlet Buffer application instance

Source: Internet
Author: User

The Servlet Buffer buffer application has a large number of editing cache technologies in the current programming language. Of course, java buffer is also a type. Let's take a look at the two servlet Buffer methods.

Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import java.net .*;

Public class MyServlet extends HttpServlet {

Public void doGet (HttpServletRequest req, HttpServletResponse res)
Throws ServletException, IOException {
Res. setBufferSize (8*1024); // 8 K buffer
Res. setContentType ("text/html ");
PrintWriter out = res. getWriter ();

Int size = res. getBufferSize (); // returns 8096 or greater

// Record the default size, in the log
Log ("The default buffer size is" + size );

Out. println ("The client won't see this ");
Res. reset ();
Out. println ("And this won't be seen if sendError () is called ");
If (req. getParameter ("important_parameter") = null ){
Res. sendError (res. SC _BAD_REQUEST, "important_parameter needed ");
}
}
}
 
<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<! DOCTYPE web-app
PUBLIC "-// Sun Microsystems, Inc. // DTD Web Application 2.2 // EN"
Http://java.sun.com/j2ee/dtds/web-app_2_2.dtd>

<Web-app>
<Servlet> <servlet-name> MyServletName </servlet-name>
<Servlet-class> MyServlet </servlet-class>


</Servlet>

<Servlet-mapping> <servlet-name> MyServletName </servlet-name>
<Url-pattern>/index.html </url-pattern>
</Servlet-mapping>
</Web-app>


 

Instance 2

Import java. io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import java. util .*;

Public class MyServlet extends HttpServlet {
Public void doGet (HttpServletRequest req, HttpServletResponse res)
Throws ServletException, IOException {

Res. setContentType ("text/html ");

// Ask for a 16 K byte response buffer; do not set the content length
Res. setBufferSize (16*1024 );

PrintWriter out = res. getWriter ();
Out. println ("<HTML> ");
Out. println ("<HEAD> <TITLE> Hello World </TITLE> </HEAD> ");
Out. println ("<BODY> ");
Out. println ("<BIG> Less than 16 K of response body </BIG> ");
Out. println ("</BODY> </HTML> ");
}
}
 
<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<! DOCTYPE web-app
PUBLIC "-// Sun Microsystems, Inc. // DTD Web Application 2.2 // EN"
Http://java.sun.com/j2ee/dtds/web-app_2_2.dtd>

<Web-app>
<Servlet> <servlet-name> MyServletName </servlet-name>
<Servlet-class> MyServlet </servlet-class>


</Servlet>

<Servlet-mapping> <servlet-name> MyServletName </servlet-name>
<Url-pattern>/index.html </url-pattern>
</Servlet-mapping>
</Web-app>


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.