public class GetWebPage extends HttpServlet
HttpServletRequest.getPathInfo()
.URLConnection.guessContentTypeFromName(String)
DocumentRootParameter
.
If the parameter is not specified for the servlet, the default
name is DocumentRoot
.LogFile
has been set, it
is used as the location for a log file for the servlet.Consideration should be given to increasing security for the servlet. The first step would be to stop file names from containing two periods in a row.
Modifier and Type | Field and Description |
---|---|
protected ServletConfig |
config
ServletConfig object as passed to the init method.
|
protected ServletContext |
context
ServletContext object containing information
for the entire web application.
|
protected String |
fileRoot
Name of root directory for reading files.
|
protected String |
fileRootParameter
Name of parameter containing the location of the document root.
|
protected int |
instanceNumber
Identifies this instance of the servlet.
|
protected String |
lineSeparator
Character string indicating end of line.
|
protected String |
logFile
Name of log file.
|
protected boolean |
logFileActive
If true, place messages in log file.
|
protected static int |
runningInstanceNumber
Keeps track of how many instances of this servlet have
been opened by the application server.
|
protected int |
runningServiceNumber
Keeps track of the different instances of the service method that are running.
|
private static long |
serialVersionUID
ID number to satisfy SERIALIZABLE interface.
|
protected boolean |
valid
Servlet has a valid configuration when true.
|
Constructor and Description |
---|
GetWebPage() |
Modifier and Type | Method and Description |
---|---|
protected void |
createLogEntry(String message) |
protected void |
createLogEntry(String message,
int serviceNumber) |
protected void |
createLogEntry(String message,
Throwable e,
int serviceNumber) |
void |
destroy()
Run when object for processing servlet is no longer needed
and is destroyed.
|
void |
init(ServletConfig configIn)
Run when object is created for processing calls to servlet.
|
static void |
main(String[] args)
This provides an error message if it is attempted to run this
class as a Java application rather than a Java servlet.
|
void |
service(HttpServletRequest req,
HttpServletResponse res)
Processes request to a servlet.
|
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
private static final long serialVersionUID
protected static int runningInstanceNumber
There is a problem in that Tomcat does not appear to treating this as a static value. The idea was that the application server could run multiple GetFile objects and would use this parameter to set the value of instanceNumber so that log files for the different objects would go to different files. Instead, the value appears to be zero each time the init method is called. The init method should only be called once for each GetFile object.
protected int instanceNumber
It was intended that this variable would identify the GetFile object if the application server was running multiple instances of the GetFile class.
protected int runningServiceNumber
protected ServletConfig config
protected ServletContext context
protected String fileRootParameter
protected boolean logFileActive
protected String lineSeparator
protected boolean valid
public GetWebPage()
public void init(ServletConfig configIn) throws ServletException
The application server can create multiple objects for a single servlet to improve performance.
init
in interface Servlet
init
in class GenericServlet
ServletException
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
protected void createLogEntry(String message)
protected void createLogEntry(String message, int serviceNumber)
protected void createLogEntry(String message, Throwable e, int serviceNumber)
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException
There can be many instances of the service method running at the same time. This must be taken into account when coding this method.
It may be necessary to change this file so that the information is recorded to a byte array and then repeated as necessary until success is achieved.
service
in class HttpServlet
req
- Object containing request informationres
- Object containing response informationIOException
HttpServletRequest
,
HttpServletResponse
,
IOException