Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
7.4 Using Persistent HTTP Connections
163
Listing 7.5 ServletUtilities.java
package coreservlets;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletUtilities {
// ... Other utilities shown earlier
/** Read a parameter with the specified name, convert it
* to an int, and return it. Return the designated default
* value if the parameter doesn't exist or if it is an
* illegal integer format.
*/
public static int getIntParameter(HttpServletRequest request,
String paramName,
int defaultValue) {
String paramString = request.getParameter(paramName);
int paramValue;
try {
paramValue = Integer.parseInt(paramString);
} catch(NumberFormatException nfe) { // null or bad format
paramValue = defaultValue;
}
return(paramValue);
}
// ...
}
7.4 Using Persistent HTTP
Connections
One of the problems with HTTP 1.0 was that it required a separate socket
connection for each request. When a Web page that includes lots of small
images or many applet classes is retrieved, the overhead of establishing all the
connections could be significant compared to the actual download time of the
documents. Many browsers and servers supported the keep alive extension
to address this problem. With this extension, the server tells the browser how
many bytes are contained in the response, then leaves the connection open
for a certain period of time after returning the document. The client detects
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved