Sun ONE Web Server 6.1 Programmer's Guide to Web Applications |
Chapter 1
Web ApplicationsThis chapter provides a basic overview of how web applications are supported in the Sun Open Net Environment (Sun ONE) Web Server 6.1, and includes the following sections:
Introducing Web ApplicationsSun ONE Web Server 6.1 supports the Java Servlet 2.3 API specification and the JavaServer Pages (JSP) 1.2 specification, which allows servlets and JSPs to be included in web applications.
A web application is a collection of servlets, JavaServer Pages, HTML documents, and other web resources that might include image files, compressed archives, and other data. A web application can be packaged into a Web ARchive file (a WAR file) or exist in an open directory structure.
In addition, Sun ONE Web Server 6.1 supports SHTML and CGI, which are non-Java 2 Platform, Enterprise Edition (J2EE platform) application components.
This section includes summaries of the following topics:
Servlets
Java servlets are server-side Java programs that application servers can run to generate content in response to a client request. Servlets can be thought of as applets that run on the server side without a user interface. Servlets are invoked through URL invocation or by other servlets.
Sun ONE Web Server 6.1 supports the Java Servlet 2.3 specification.
Note
Java Servlet API version 2.3 is fully backward compatible with versions 2.1 and 2.2, so all existing servlets will continue to work without modification or recompilation.
To develop servlets, use Sun's Java Servlet API. For information about using the Java Servlet API, see the documentation provided by Sun at:
http://java.sun.com/products/servlet/index.jsp
For the Java Servlet 2.3 specification, please visit:
http://java.sun.com/products/servlet/download.html
For information about developing servlets in Sun ONE Web Server, see "Using Servlets."
JavaServer Pages (JSP)
Sun ONE Web Server 6.1 supports the JavaServer Pages (JSP) 1.2 specification.
A JSP is a page, much like an HTML page, that can be viewed in a web browser. However, in addition to HTML tags, it can include a set of JSP tags and directives intermixed with Java code that extend the ability of the web page designer to incorporate dynamic content in a page. These additional features provide functionality such as displaying property values and using simple conditionals.
One of the main benefits of JSPs is that they are like HTML pages. The web page designer simply writes a page that uses HTML and JSP tags and puts it on his or her web server. The page is compiled automatically when it is deployed. The web page designer needs to know little about Java classes and Java compilers. Sun ONE Web Server supports precompilation of JSPs, however, and this is recommended for production servers.
JSP pages can access full Java functionality by:
Servlets are Java classes that must be compiled, but they can be defined and compiled by a Java programmer, who then publishes the interface to the servlet. The web page designer can access a precompiled servlet from a JSP page.
Sun ONE Web Server 6.1 supports JSP tag libraries and standard portable tags.
For information about creating JSPs, see Sun's JavaServer Pages web site at:
http://java.sun.com/products/jsp/index.jsp
For information about developing JSPs in Sun ONE Web Server, see "Using JavaServer Pages."
SHTML
HTML files can contain tags that are executed on the server. In addition to supporting the standard server-side tags, or SSIs, Sun ONE Web Server 6.1 allows you to embed servlets and define your own server-side tags. For more information, see the Sun ONE Web Server 6.1 Programmer’s Guide.
CGI
Common Gateway Interface (CGI) programs run on the server and generate a response to return to the requesting client. CGI programs can be written in various languages, including C, C++, Java, Perl, and as shell scripts. CGI programs are invoked through URL invocation. Sun ONE Web Server complies with the version 1.1 CGI specification. For more information, see the Sun ONE Web Server 6.1 Programmer’s Guide.
Creating a Web ApplicationTo create a web application:
- Create a directory for all of the web application's files. This is the web application's document root.
- Create any needed HTML files, image files, and other static content. Place these files in the document root directory or a subdirectory where they can be accessed by other parts of the application.
- Create any needed JSP files. For more information, see "Using JavaServer Pages."
- Create any needed servlets. For more information, see "Using Servlets."
- Compile the servlets. For details about precompiling JSPs, see "Compiling JSPs: The Command-Line Compiler."
- Organize the web application as described in "Web Application Structure."
- Create the deployment descriptor files. For more information, see "Creating Web Deployment Descriptors."
- Package the web application in a .war file if desired. This is optional. For example:
jar -cvf module_name.war *
- Deploy the web application. For more information, see "Deploying Web Applications."
You can create a web application manually, or you can use Sun ONE Studio.
Securing a Web ApplicationYou can write secure web applications for the Sun ONE Web Server with components that perform user authentication and access authorization. You can build security into web applications using the following mechanisms:
For detailed information about these mechanisms, see "Securing Web Applications."
Deploying a Web ApplicationWeb application deployment descriptor files are packaged within .war files. They contain metadata, plus information that identifies the servlet or JSP and establishes its application role. For more information about these descriptor files, see "Deploying Web Applications."
Virtual ServersA virtual server is a virtual web server that uses a unique combination of IP address, port number, and host name to identify it. You might have several virtual servers, all of which use the same IP address and port number but are distinguished by their unique host names.
When you first install Sun ONE Web Server, a default virtual server is created. You can also assign a default virtual server to each new HTTP listener you create. For details, see the Sun ONE Web Server 6.1 Administrator's Guide.
Web applications can be hosted under virtual servers.
Default Web ApplicationsA web application that is deployed in a virtual server at a URI ‘/’ becomes the default web application for that virtual server. For details, see "Virtual Servers." To access the default web application for a virtual server, point your browser to the URL for the virtual server, but do not supply a context root. For example:
http://myvirtualserver:3184/
If none of the web applications under a virtual server are deployed at the URI ‘/’, the virtual server serves HTML or JSP content from its document root, which is usually install_dir/docs. To access this HTML or JSP content, point your browser to the URL for the virtual server, and do not supply a context root but rather specify the target file. For example:
http://myvirtualserver:3184/hellothere.jsp
Servlet and JSP CachingThe Sun ONE Web Server has the ability to cache servlet or JSP results in order to make subsequent calls to the same servlet or JSP faster.
The Sun ONE Web Server caches the request results for a specific amount of time. In this way, if another data call occurs, the Sun ONE Web Server can return the cached data instead of performing the operation again. For example, if your servlet returns a stock quote that updates every 5 minutes, you set the cache to expire after 300 seconds.
For more information about response caching as it pertains to servlets, see "Caching Servlet Results."
For more information about JSP caching, see "JSP Cache Tags."
Database Connection PoolingDatabase connection pooling enhances the performance of servlet or JSP database interactions. For more information about Java DataBase Connectivity (JDBC), see the Sun ONE Web Server 6.1 Administrator’s Guide.
Configuring the Web ContainerYou can configure logging in the web container for the entire server by:
Web Application SamplesSun ONE Web Server 6.1 includes a set of sample web applications, which can be found in the following directory:
server_root/plugins/java/samples/webapps/
The directory contains the directories and samples listed in the following table. It also contains an index.html file that provides more information about configuring and deploying the samples.
You can also deploy these examples using the wdeploy utility. For more information about this utility, see "Deploying Web Applications."