D Web Application Best Practices
This appendix includes the following sections:
CGI Best Practices
Review the CGI best practices with respect to calling a subscript.
-
You can use
sh subscript.sh
for both exploded (unarchived) Web applications and archived Web applications (WAR files). -
You can use
sh $PWD/subscript.sh
for both exploded (unarchived) Web applications and archived Web applications (WAR files). -
You can use
sh $DOCUMENT_ROOT/$PATH/subscript.sh
for exploded (unarchived) Web applications. You cannot use it, however, for archived Web applications (WAR files). This is due to the fact that the document root might point you to the root of your WAR file, and the scripting language cannot open that WAR file and locate thesubscript.sh
needed for execution. This is true not only forsh
, but for any scripting language.
Servlet Best Practices
When writing HTTP servlets, review the recommended best practices.
-
Compile your servlet classes into the
WEB-INF/classes
directory of your Web application. -
Make sure your servlet is registered in the Java EE standard Web applications deployment descriptor (
web.xml)
. -
When responding to a request for a servlet, WebLogic Server checks the time stamp of the servlet class file prior to applying any filters associated with the servlet, and compares it to the servlet instance in memory. If a newer version of the servlet class is found, WebLogic Server re-loads all servlet classes before any filtering takes place. When the servlets are re-loaded, the
init()
method of the servlet is called. All servlets are reloaded when a modified servlet class is discovered due to the possibility that there are interdependencies among the servlet classes.You can set the interval (in seconds) at which WebLogic Server checks the time stamp with the
Servlet Reload
attribute. This attribute is set on theFiles
tab of your Web application, in the Administration Console. If you set this attribute to zero, WebLogic Server checks the time stamp on every request, which can be useful while developing and testing servlets but is needlessly time consuming in a production environment. If this attribute is set to-1
, WebLogic Server does not check for modified servlets.
Best Practice When Subclassing ServletResponseWrapper
Java EE provides the class javax.servlet.ServletResponseWrapper
, which you can subclass in your Servlet to adapt its response.
Oracle recommends that if you create your own response wrapper by subclassing the ServletResponseWrapper
class, you should always override the flushBuffer()
and resetBuffer()
methods. Not doing so might result in the response being committed prematurely.