Introducing Web Applications

Sun 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.

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:

JavaServer Pages (JSP)

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:

Embedding Java code directly in scriptlets in the page

Using server-side tags that include Java servlets

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.

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 Application

To 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.

You can create a web application manually, or you can use Sun ONE Studio.

Securing a Web Application

You 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:

Deploying a Web Application

Web 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 Servers

A 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 Applications

A 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 Caching

The 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.