Oracle8i
Oracle Servlet
Engine User's Guide Release 3 (8.1.7) A83720-01 |
|
This chapter uses examples and discussion to describe the OSE developer techniques and tools. The following topics are in this chapter:
A Web service contains one or more domains, depending on the configuration of the service. A newly created Web domain contains one servlet context, default
. It serves contents for all requests that do not map to another servlet context. You can create specific servlets and servlet contexts for your own applications (see Figure 7-1, "JNDI default Servlet Context in the JNDI Namespace").
JNDI namespace directory structure in parallel to another servlet context. The same structure requirements apply to both branches of the JNDI namespace tree. See Figure 1-2 and Figure 1-3 for visual examples of single and multiple domains.
default
Servlet Context in the JNDI Namespace
Use the createwebservice
command to define properties of the service. The Oracle Java Tools Reference has a detailed description of this command.
In a single domain case, you do have neither an IP or a virtual host domain. The domain root is the service root. If you have a service configured to be a multi-domain service, as either a virtual host or an IP address, the domain will be rooted in the service root. If the service has both types of domains, IP address and a virtual host, the IP address is rooted in the service root, and the virtual host is contained in the IP address domain (see Figure 1-3, "Multi-Domain, Multi-Homed Example with Virtual Hosts In the Structure").
These domains are created by the createwebdomain
command. See the Oracle Java Tools Reference for syntax and argument details.
Ports are associated with the corresponding presentation either statically or by using the dynamic registration commands. To support HTTPS, associate an additional SSL endpoint to the Web service.
Use the addendpoint
command to configure the ports that are to be associated with the service (see Oracle Java Tools Reference for syntax and arguments).
This section describes how to create, change, and delete a servlet context.
Create new servlet contexts with the session shell createcontext
command.
contexts
directory to create a servlet context.
config
object.
config
object, making the new servlet context accessible to HTTP clients.
createcontext
defines and sets up some or all the following properties:
In Example 7-1, "Creating a Servlet Context Named, winecellar", the servlet context handles all HTTP requests beginning with, http://<
host-name
>:8080/cellar
winecellar
Enter:
|
|
|
|
|
|
|
virtualPath |
domainName |
servlet context |
Enter:
$
ls /webdomains/contexts
./ ../ default/ winecellar/
$
getgroup /webdomains/config contexts
/cellar=winecellar
Remove a servlet context and all servlets in the context with the session shell tool destroycontext
command. The mapping in the domain config
object is removed as well.
A servlet context encapsulates the notion of a web application. A servlet context contains several entries that represent its configuration and contents. You can see the entries with the session shell tool.
winecellar
Representing Configuration
and Content
$
cd /webdomains/contexts/winecellar
$
ls
./
../
config
doc_root
named_servlets/
defaultservlet policy httpSecurity
The config
entry has a set of properties controlling the behavior of the servlet context. You can see and modify the config
object with the session shell commands that manage object properties. See Oracle Java Tools Reference for more information.
The doc_root
object is a JNDI object representing an instance of class SYS:oracle.aurora.namespace.filesystem.FSContextImpl
that serves as a link to the file system. The doc_root
object is where the static content is located. It has one property known as FSContextURL
. The file system path of the static contents of the servlet context, is stored in the FSContextURL
property.
The named_servlets
subdirectory contains the servlets published in the servlet context. Each published servlet is a JNDI object representing an instance of class SYS:oracle.aurora.mts.ServletActivation
.
If there is an entry in the servlet context named, defaultServlet
, that servlet is used when no other servlet matches the request. If there is no entry in the servlet context for a default servlet, one is provided by the containing service.
The policy
directory contains security configuration entries. See details in Chapter 8, "Security HTTP Administration".
The security servlet, httpSecurity
, functions as the first filter for all requests. This servlet handles security by raising an exception or not raising an exception and allowing the request processing to proceed. See details in Chapter 8, "Security HTTP Administration".
This section contains the full list of groups and properties that a servlet context config
object supports.
The group, context.properties
, lists a set of properties that control the servlet context.
$
getproperties config
--group--=context.properties
context.browse.dirs=true
context.welcome.names=index.html
context.accept.charset=ISO-8859-1
context.accept.language=en
context.default.languages=*
context.default.charsets=*
--group--=context.params
...--group--=context.mime
java=text/plain
html=text/html
...
$
addgroupentry config context.properties context.browse.dirs false
$
getgroup config context.properties
context.browse.dirs=false
context.welcome.names=index.html
context.accept.charset=ISO-8859-1
context.accept.language=en
context.default.languages=*
context.default.charsets=*
The context.params
group is a list of arbitrary name/value pairs that are accessible at runtime by the servlet context getAttribute
method.
If you have the following parameters:
$
getgroup config context.properties
details=high
You can access the details parameter in a servlet as follows:
public void doGet (HttpServletRequest request, HttpServletResponse response)
... {
...
String details = getServletContext().getAttribute ("details");
if (details.equals ("high")) {
...
}
The group context.mime
lists the MIME types that the servlet context supports. This group has the same format as the MIME types group in the Web domain configuration.
When you publish servlets, you associate them with virtual paths, and you can see these virtual paths with the session shell getgroup
command. See the section, "JNDI default Servlet Context in the JNDI Namespace" for more information.
The group context.servlets
lists the virtual path mapping for the published servlets. It contains a list of name/value pairs, where the name part is the virtual path, and the value part is the name of a servlet to handle the virtual path. The servlet name is relative to the named_servlets
directory of the servlet context. The name portion of the pair contains either a virtual path or a wild-card name.
The group context.error.uris
associates HTTP error codes with URIs within the servlet context that are used to report errors to the HTTP clients. Often, these URIs are handled by the default servlet and are relative to the doc_root
parameter of the servlet context.
$
getgroup config context.error.uris
401=/system/errors/401.html
403=/system/errors/403.html
404=/system/errors/404.html
406=/system/errors/406.html
500=/errors/internal
A servlet is published once it has a servlet activation entry in the named_servlets
directory and the virtual path that is mapped in the servlet context config
object.
This section discusses how to manage the servlets published in the OSE.
The session shell publishservlet
and unpublishservlet
commands modify the named_servlets
directory and the servlet context config object. The servlets are created (published) or removed with their associated paths and names.
Published servlets are JNDI objects of class SYS:oracle.aurora.mts.ServletActivation
. To be accessible from an HTTP client, servlets must be associated with a virtual path or a star-name, in their servlet context.
$
publishservlet -virtualpath /tastings \
/webdomains/contexts/winecellar tastingServlet \
SCOTT:winemasters.tasting.Tasting
Note: The backslash is a line continuation aide. It is a shell tool command line convention to assist with very long entries. |
# Verify the servlet is here
$
getproperties /webdomains/contexts/winecellar/named_servlets/tastingServlet servlet.class=SCOTT:winemasters.tasting.Tasting# Verify the virtual path mapping
$
getgroup /webdomains/contexts/winecellar/config context.servlets
/errors/internal=internalError /tastings=tastingServlet
A newly published servlet has only one property, the servlet.class
. The servlet.class
specifies the full name of the servlet class: the schema and the fully qualified path within the schema. If no schema is specified, the current schema is used.
You can add additional properties with session shell commands and access additional properties from the servlet code with the getInitParameter()
method call.
$
setproperties invoker \
"servlet.class=SCOTT:winemasters.tasting.Tasting
details=high
style=pa
rker"$
getproperties invoker
servlet.class=SCOTT:winemasters.tasting.Tasting
details=high
style=parker
You can access the servlet properties with the following code:
public void doGet (HttpServletRequest request, HttpServletResponse response) { ... String details = getServletConfig().getInitParameter ("details"); if (details.equals ("high")) { ... }
Once you have configured OSE, you can begin writing and deploying servlets and JSPs.
Note:
A prerequisite for this section is understanding the "Endpoints" section in chapter "Architecture". |
We support the Servlet 2.2 specification.
The following steps describe the method of writing and publishing a servlet:
A servlet book will give a full spectrum of examples and tutorials. Please see a servlet book for assistance in writing the code.
To compile the servlet, you must have the following jar(s) in your CLASSPATH:
$(ORACLE_HOME)/jis/lib/servlet.jar
- %(ORACLE_HOME)/jdbc/lib/classes12.zip
- % javac -classpath .:$(ORACLE_HOME)/jis/lib/servlet.jar HelloWorld.java
Load the servlet with the loadjava
command. See the documentation on loadjava
in the "JServer Concepts Manual".
%
loadjava -u scott/tiger -r HelloWorld.class
Here we publish in the default context. We are mapping the servlet to the virtualpath /hello.
$ publishservlet -virtualpath /hello /webdomains/contexts/default helloServlet SCOTT:HelloWorld
If you change the servlet, you must reload it in the database, but it is not necessary to republish the servlet in the Web server.
You can now see the servlet in a Web browser, using the URL:http://<host>:8080/hello
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|