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.shfor both exploded (unarchived) Web applications and archived Web applications (WAR files).
You can use
sh $PWD/subscript.shfor both exploded (unarchived) Web applications and archived Web applications (WAR files).
You can use
sh $DOCUMENT_ROOT/$PATH/subscript.shfor 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 the
subscript.shneeded for execution. This is true not only for
sh, 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/classesdirectory of your Web application.
Make sure your servlet is registered in the Java EE standard Web applications deployment descriptor (
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 Reloadattribute. This attribute is set on the
Filestab 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
resetBuffer() methods. Not doing so might result in the response being committed prematurely.