More interaction with the server. Once a

More interaction with the server. Once a CGI program begins execution, it is untethered from its server. The only communication path available to the program is its standard output. A servlet, however, can work with the server. As discussed in the last chapter, a servlet operates either within the server (when possible) or as a connected process outside the server (when necessary). Using this connectivity, a servlet can make ad hoc requests for calculated information that only the server can provide. For example, a servlet can have its server do arbitrary path translations, taking into consideration the server’s aliases and virtual paths. If you’re coming to servlets from CGI, Table 4-1 is a ‘’cheat sheet” you can use for your migration. It lists each CGI environment variable and the corresponding HTTP servlet method. Table 4-1. CGI Environment Variables and the Corresponding Servlet Methods CGI Environment Variable HTTP Servlet Method SERVER_NAME req.getServerName() SERVER_SOFTWARE getServletContext().getServerInfo() SERVER_PROTOCOL req.getProtocol() SERVER_PORT req.getServerPort() REQUEST_METHOD req.getMethod() PATH_INFO req.getPathInfo() PATH_TRANSLATED req.getPathTranslated() SCRIPT_NAME req.getServletPath() DOCUMENT_ROOT req.getRealPath(”/”) QUERY_STRING req.getQueryString() REMOTE_HOST req.getRemoteHost() REMOTE_ADDR req.getRemoteAddr() AUTH_TYPE req.getAuthType() REMOTE_USER req.getRemoteUser() CONTENT_TYPE req.getContentType() CONTENT_LENGTH req.getContentLength() HTTP_ACCEPT req.getHeader(”Accept”) HTTP_USER_AGENT req.getHeader(”User-Agent”) HTTP_REFERER req.getHeader(”Referer”) In the rest of this chapter, we’ll see how and when to use these methods and several other methods that have no CGI counterparts. Along the way, we’ll put the methods to use in some real servlets. Initialization Parameters
Quick Hint: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting plans

Comments are closed.