Part I Development Tasks and Tools
1. Setting Up a Development Environment
3. Using Ant with Enterprise Server
Part II Developing Applications and Application Components
7. Using the Java Persistence API
8. Developing Web Applications
The CacheKeyGenerator Interface
Instantiating and Removing Servlets
JSP Tag Libraries and Standard Portable Tags
Options for Compiling JSP Files
Creating and Managing Sessions
HTTP Sessions, Cookies, and URL Rewriting
Saving Sessions During Redeployment
The Grizzly Implementation of Comet
Client Technologies to Use With Comet
Creating a Comet-Enabled Application
Creating the Deployment Descriptor
Deploying and Running a Comet-Enabled Application
To Write, Deploy, and Run the Client
Advanced Web Application Features
Using the default-web.xml File
To Use the default-web.xml File
Configuring Logging and Monitoring in the Web Container
9. Using Enterprise JavaBeans Technology
10. Using Container-Managed Persistence
13. Developing Lifecycle Listeners
Part III Using Services and APIs
14. Using the JDBC API for Database Access
15. Using the Transaction Service
16. Using the Java Naming and Directory Interface
This section includes summaries of the following topics:
This section covers internationalization as it applies to the following:
To set the default locale of the entire Enterprise Server, which determines the locale of the Administration Console, the logs, and so on, use the Administration Console. Select the Enterprise Server component, the Advanced tab, and the Domain Attributes tab. Then type a value in the Locale field. For details, click the Help button in the Administration Console.
This section explains how the Enterprise Server determines the character encoding for the servlet request and the servlet response. For encodings you can use, see http://java.sun.com/javase/6/docs/technotes/guides/intl/encoding.doc.html.
When processing a servlet request, the server uses the following order of precedence, first to last, to determine the request character encoding:
A hidden field in the form, specified by the form-hint-field attribute of the parameter-encoding element in the sun-web.xml file
The default-charset attribute of the parameter-encoding element in the sun-web.xml file
The default, which is ISO-8859-1
For details about the parameter-encoding element, see parameter-encoding in Sun GlassFish Enterprise Server v3 Application Deployment Guide.
When processing a servlet response, the server uses the following order of precedence, first to last, to determine the response character encoding:
The default, which is ISO-8859-1
You can set virtual server properties in the following ways:
You can define virtual server properties using the asadmin create-virtual-server command. For example:
asadmin create-virtual-server --hosts localhost --property authRealm=ldap MyVS
For details and a complete list of virtual server properties, see create-virtual-server(1).
You can define virtual server properties using the asadmin set command. For example:
asadmin set server-config.http-service.virtual-server.MyVS.property.authRealm="ldap"
For details, see set(1).
You can define virtual server properties using the Administration Console. Select the HTTP Service component under the relevant configuration, select Virtual Servers, and select the desired virtual server. Select Add Property, enter the property name and value, check the enable box, and select Save. For details and a complete list of virtual server properties, click the Help button in the Administration Console.
Some virtual server properties can be set for a specific web application. For
details, see sun-web-app in Sun GlassFish Enterprise Server v3 Application Deployment Guide.
The Servlet specification recommends that a web application class loader look in the local class loader before delegating to its parent. To make the web application class loader follow the delegation model in the Servlet specification, set delegate="false" in the class-loader element of the sun-web.xml file. It’s safe to do this only for a web module that does not interact with any other modules.
The default value is delegate="true", which causes the web application class loader to delegate
in the same manner as the other class loaders. Use delegate="true" for
a web application that accesses EJB components or that acts as a web
service client or endpoint. For details about sun-web.xml, see Sun GlassFish Enterprise Server v3 Application Deployment Guide.
For a number of packages, including java.* and javax.*, symbol resolution is always delegated to the parent class loader regardless of the delegate setting. This prevents applications from overriding core Java runtime classes or changing the API versions of specifications that are part of the Java EE platform.
For general information about class loaders, see Chapter 2, Class Loaders.
You can use the default-web.xml file to define features such as filters and security constraints that apply to all web applications.
For example, directory listings are disabled by default for added security. To enable directory listings, in your domain's default-web.xml file, search for the definition of the servlet whose servlet-name is equal to default, and set the value of the init-param named listings to true. Then redeploy your web application if it has already been deployed, or restart the server.
<init-param> <param-name>listings</param-name> <param-value>true</param-value> </init-param>
If listings is set to true, you can also determine how directory listings are sorted. Set the value of the init-param named sortedBy to NAME, SIZE, or LAST_MODIFIED. Then redeploy your web application if it has already been deployed, or restart the server.
<init-param> <param-name>sortedBy</param-name> <param-value>LAST_MODIFIED</param-value> </init-param>
The mime-mapping elements in default-web.xml are global and inherited by all web applications. You can override these mappings or define your own using mime-mapping elements in your web application's web.xml file. For more information about mime-mapping elements, see the Servlet specification.
You can use the Administration Console to edit the default-web.xml file. For details, click the Help button in the Administration Console. As an alternative, you can edit the file directly using the following steps.
Place the JAR file for the filter, security constraint, or other feature in the domain-dir/lib directory.
Edit the domain-dir/config/default-web.xml file to refer to the JAR file.
Restart the server.
For information about configuring logging and monitoring in the web container using the Administration Console, click the Help button in the Administration Console. Logging and Monitor tabs are accessible from the Application Server page.
In all Editions of the Enterprise Server, the Enumeration from request.getHeaders() contains multiple elements (one element per request header) instead of a single, aggregated value.
The header names used in HttpServletResponse.addXXXHeader() and HttpServletResponse.setXXXHeader() are returned as they were created.
You can configure custom valves and Catalina listeners for web modules or virtual servers by defining properties. A valve class must implement the org.apache.catalina.Valve interface from Tomcat or previous Enterprise Server releases, or the org.glassfish.web.valve.GlassFishValve interface from the current Enterprise Server release. A listener class for a virtual server must implement the org.apache.catalina.ContainerListener or org.apache.catalina.LifecycleListener interface. A listener class for a web module must implement the org.apache.catalina.ContainerListener, org.apache.catalina.LifecycleListener, or org.apache.catalina.InstanceListener interface.
In the sun-web.xml file, valve and listener properties for a web module look like this:
<sun-web-app ...> ... <property name="valve_1" value="org.glassfish.extension.Valve"/> <property name="listener_1" value="org.glassfish.extension.MyLifecycleListener"/> </sun-web-app>
You can define these same properties for a virtual server. For more information,
see Virtual Server Properties.
An alternate document root (docroot) allows a web application to serve requests for certain resources from outside its own docroot, based on whether those requests match one (or more) of the URI patterns of the web application's alternate docroots.
To specify an alternate docroot for a web application or a virtual server,
use the alternatedocroot_n property, where n is a positive integer that allows specification of
more than one. This property can be a subelement of a sun-web-app element
in the sun-web.xml file or a virtual server property. For more information about
these elements, see sun-web-app in Sun GlassFish Enterprise Server v3 Application Deployment Guide or .
A virtual server's alternate docroots are considered only if a request does not map to any of the web modules deployed on that virtual server. A web module's alternate docroots are considered only once a request has been mapped to that web module.
If a request matches an alternate docroot's URI pattern, it is mapped to the alternate docroot by appending the request URI (minus the web application's context root) to the alternate docroot's physical location (directory). If a request matches multiple URI patterns, the alternate docroot is determined according to the following precedence order:
Exact match
Longest path match
Extension match
For example, the following properties specify three sun-web.xml docroots. The URI pattern of the first alternate docroot uses an exact match, whereas the URI patterns of the second and third alternate docroots use extension and longest path prefix matches, respectively.
<property name="alternatedocroot_1" value="from=/my.jpg dir=/srv/images/jpg"/> <property name="alternatedocroot_2" value="from=*.jpg dir=/srv/images/jpg"/> <property name="alternatedocroot_3" value="from=/jpg/* dir=/src/images"/>
The value of each alternate docroot has two components: The first component, from, specifies the alternate docroot's URI pattern, and the second component, dir, specifies the alternate docroot's physical location (directory).
Suppose the above examples belong to a web application deployed at http://company22.com/myapp. The first alternate docroot maps any requests with this URL:
http://company22.com/myapp/my.jpg
To this resource:
/svr/images/jpg/my.jpg
The second alternate docroot maps any requests with a *.jpg suffix, such as:
http://company22.com/myapp/*.jpg
To this physical location:
/svr/images/jpg
The third alternate docroot maps any requests whose URI starts with /myapp/jpg/, such as:
http://company22.com/myapp/jpg/*
To the same directory as the second alternate docroot.
For example, the second alternate docroot maps this request:
http://company22.com/myapp/abc/def/my.jpg
To:
/srv/images/jpg/abc/def/my.jpg
The third alternate docroot maps:
http://company22.com/myapp/jpg/abc/resource
To:
/srv/images/jpg/abc/resource
If a request does not match any of the target web application's alternate docroots, or if the target web application does not specify any alternate docroots, the request is served from the web application's standard docroot, as usual.
You can define a context.xml file for all web applications, for web applications assigned to a specific virtual server, or for a specific web application.
To define a global context.xml file, place the file in the domain-dir/config directory and name it context.xml.
Use the contextXmlDefault property to specify the name and the location, relative to domain-dir, of the context.xml file for a specific virtual server. Specify this property in one of the following ways:
In the Administration Console, open the HTTP Service component under the relevant configuration. Open the Virtual Servers component and scroll down to the bottom of the page. Enter contextXmlDefault as the property name and the path and file name relative to domain-dir as the property value.
Use the asadmin create-virtual-server command. For example:
asadmin create-virtual-server --property contextXmlDefault=config/vs1ctx.xml vs1
Use the asadmin set command for an existing virtual server. For example:
asadmin set server-config.http-service.virtual-server.vs1.property.contextXmlDefault=config/myctx.xml
To define a context.xml file for a specific web application, place the file in the META-INF directory and name it context.xml.
For more information about virtual server properties, see Virtual Server Properties. For more information about
the context.xml file, see The Context Container. Context parameters, environment entries, and resource definitions in
context.xml are supported in the Enterprise Server.
To enable WebDav in the Enterprise Server, you edit the web.xml and sun-web.xml files as follows.
First, enable the WebDav servlet in your web.xml file:
<servlet> <servlet-name>webdav</servlet-name> <servlet-class>org.apache.catalina.servlets.WebdavServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>0</param-value> </init-param> <init-param> <param-name>listings</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>readonly</param-name> <param-value>false</param-value> </init-param> </servlet>
Then define the servlet mapping associated with your WebDav servlet in your web.xml file:
<servlet-mapping> <servlet-name>webdav</servlet-name> <url-pattern>/webdav/*</url-pattern> </servlet-mapping>
To protect the WebDav servlet so other users can't modify it, add a security constraint in your web.xml file:
<security-constraint> <web-resource-collection> <web-resource-name>Login Resources</web-resource-name> <url-pattern>/webdav/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>Admin</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> <login-config> <auth-method>BASIC</auth-method> <realm-name>default</realm-name> </login-config> <security-role> <role-name>Admin</role-name> </security-role> </security-constraint>
Then define a security role mapping in your sun-web.xml file:
<security-role-mapping> <role-name>Admin</role-name> <group-name>Admin</group-name> </security-role-mapping>
If you are using the file realm, create a user and password. For example:
asadmin create-file-user --groups Admin --authrealmname default admin
Enable the security manager as described in Enabling and Disabling the Security Manager.
You can now use any WebDav client by connecting to the WebDav servlet URL, which has this format:
http://host:port/context-root/webdav/file
For example:
http://localhost:80/glassfish-webdav/webdav/index.html
You can add the WebDav servlet to your default-web.xml file to enable it for all applications, but you can't set up a security role mapping to protect it.
To enable SSI (server-side includes) processing for a specific web module, add the SSIServlet to your web.xml file as follows:
<web-app> <servlet> <servlet-name>ssi</servlet-name> <servlet-class>org.apache.catalina.ssi.SSIServlet</servlet-class> </servlet> ... <servlet-mapping> <servlet-name>ssi</servlet-name> <url-pattern>*.shtml</url-pattern> </servlet-mapping> ... <mime-mapping> <extension>shtml</extension> <mime-type>text/html</mime-type> </mime-mapping> </web-app>
To enable SSI processing for all web modules, un-comment the corresponding sections in the default-web.xml file.
If the mime-mapping is not specified in web.xml, Enterprise Server attempts to determine the MIME type from default-web.xml or the operating system default.
You can configure the following init-param values for the SSIServlet.
|
For more information about SSI, see http://httpd.apache.org/docs/2.2/mod/mod_include.html.
To enable CGI (common gateway interface) processing for a specific web module, add the CGIServlet to your web.xml file as follows:
<web-app> <servlet> <servlet-name>cgi</servlet-name> <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> </servlet> ... <servlet-mapping> <servlet-name>cgi</servlet-name> <url-pattern>/cgi-bin/*</url-pattern> </servlet-mapping> </web-app>
To enable CGI processing for all web modules, un-comment the corresponding sections in the default-web.xml file.
Package the CGI program under the cgiPathPrefix. The default cgiPathPrefix is WEB-INF/cgi. For security,
it is highly recommended that the contents and binaries of CGI programs be
prohibited from direct viewing or download. For information about hiding directory listings, see
Using the default-web.xml File.
Invoke the CGI program using a URL of the following format:
http://host:8080/context-root/cgi-bin/cgi-name
For example:
http://localhost:8080/mycontext/cgi-bin/hello
You can configure the following init-param values for the CGIServlet.
|
To work with a native executable, do the following:
Set the value of the init-param named executable to an empty String in the web.xml file.
Make sure the executable has its executable bits set correctly.
Use directory deployment to deploy the web module. Do not deploy it as a WAR file, because the executable bit information is lost during the process of jar and unjar. For more information about directory deployment, see the Sun GlassFish Enterprise Server v3 Application Deployment Guide.