This chapter provides a basic overview of how web applications are supported in Web Server. This chapter includes the following sections:
Web Server supports the Java™ Servlet 2.5 API specification and the JavaServer Pages™ (JSP™) 2.1 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 include image files, compressed archives, and other data. A web application can be packaged into a web archive (WAR) file or exist in an open directory structure.
Web Server 7.0 also supports, SHTML and CGI, which are not Java Platform, Enterprise Edition (Java EE) application components. For more information about APIs and programming technologies, see Sun Java System Web Server 7.0 Update 3 Developer’s Guide.
This section describes how to create, secure, and deploy web applications using Web Server.
This section lists the general actions to create a web application, and provides pointers to more information.
Create a directory for all of the web application's files. This directory 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 Chapter 5, Developing JavaServer Pages
Create any needed servlets.
For more information, see Chapter 4, Developing Servlets.
Compile the servlets.
For details about precompiling JSPs, see Compiling JSPs Using 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.
(Optional) Package the web application in a .war file. 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 Java System Enterprise Studio. For more information about developing web applications in Sun Java Enterprise Studio, see http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/helloweb.html
You can write secure web applications for the Sun Java System Web Server with components that perform user authentication and access authorization. You can build security into web applications using the following mechanisms:
User authentication by servlets
User authentication for single sign-on
User authorization by servlets
Requesting the client certificate
For detailed information about these mechanisms, see Chapter 8, Securing Web Applications.
A web application is a collection of servlets, JSP, 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. For more information, see Chapter 9, Deploying Web Applications.
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 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 Sun Java System Web Server 7.0 Update 3 Administrator’s Guide.
A web application that is deployed in a virtual server at a URL / becomes the default web application for that virtual server. To access the default web application for a virtual server, type 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 instance_dir/docs. To access this HTML or JSP content, point your browser to the URL for the virtual server specify the target file rather than a context root. For example:
http://myvirtualserver:3184/hellothere.jsp
The Web Server can cache servlet or JSP results to make subsequent calls to the same servlet or JSP page faster.
For more information about response caching as it pertains to servlets, see Caching Servlet Results.
JSP cache tags enable you to cache JSP page fragments within the Java engine. Each can be cached using different cache criteria. For example, if you have page fragments to view stock quotes and weather information, you can cache the stock quote fragment for 15 minutes, and the weather report fragment for 25 minutes.
For more information about JSP caching, see JSP Cache Tags.
Database connection pooling enhances the performance of servlet or JSP database interactions. For more information about the JavaTM DataBase Connectivity (JDBCTM) software, see Configuring JDBC Resources in Sun Java System Web Server 7.0 Update 3 Administrator’s Guide.
The simplest connection pool can be configured by using the given. In this example, the connection pool is assigned to use the ORACLE JDBC driver.
In this example procedure, the connection pool uses the ORACLE JDBC driver.
Start wadm
$ ./bin/wadm --user=admin Please enter admin-user-password>user-admin-password Sun Java System Web Server 7.0 B01/02/2006 14:22 wadm> |
Verify the list of available configurations.
wadm>list-configs |
Create the jdbc-resource configuration.
For more information about all possible elements, see Sun Java System Web Server 7.0 Administrator's Configuration File Reference.
wadm>create-jdbc-resource --config=test --datasource-class=oracle.jdbc.pool.OracleDataSource jdbc/MyPool |
Add properties to jdbc-resource.
Properties are primarily used to configure the driver's vendor-specific properties. In the following example, the values for the properties url, user, and password are added to jdbc-resource.
wadm>list-jdbc-resource-userprops --config=test --jndi-name=jdbc/MyPool password=mypassword user=myuser url=jdbcZ:oracle:thin:@hostname:1421MYSID |
Enable the connection validation.
wadm>set-jdbc-resource-prop --config=test --jndi-name=jdbc/MyPool connection-validation-table-name=test connection-validation=table CLI201 Command "set-jdbc-resource-prop" ran successfully |
Change the pool setting.
In this example, the maximum number of connections is set to 100.
wadm>set-jdbc-resource-prop --config=test --jndi-name=jdbc/MyPool max-connections=100 CLI201 Command "set-jdbc-resource-prop" ran successfully. |
Deploy the configuration.
wadm>deploy-config test CLI201 Command "deploy-config" ran successfully. |
You can install a JDBC driver with Java Archive (JAR) files in one of the following ways:
Copy the driver's JAR file into the server's instance library directory. JAR files in the instance library directory will automatically load and available for server.
Modify the JVM class-path- suffix to include JDBC drivers jar file. The new value will overwrite the old value of the element. For example, wadm> set-jvm-prop --config=test class-path-suffix=/export/home/lib/classes12.jar
Sun Java System Web Server 7.0 includes a set of sample applications, which can be found in the install-dir/samples directory. All the sample applications are arranged in a specific and well-defined directory structure. The sample application included as part of the Sun Java System Web Server are packaged into consistent directory structure as elaborated below:
NSAPI — This directory contains examples of source code for Server Application Functions (SAFs) which helps you get started with programming your Sun Java System Web Server.
Directory path: install-dir/samples/nsapi
Java — This directory contains samples which help to create, deploy and run various java applications.
Directory path: install-dir/samples/java
FastCGI — This directory contains samples, which demonstrates the use of PHP Add-On and FastCGI plug-in on Web Server 7.0.
Directory path: install-dir/samples/fastcgi
Administration CLI — This directory contains scripts that one can run using the wadm command line utility. The utility can be found at <install-root>/bin/wadm. wadm is built on a Tcl engine and hence supports Tcl scripting. Some of these samples demonstrate how scripts can be used to perform common administrative tasks. They also demonstrate how new utilities can be built on top of existing commands.
Directory path: install-dir/samples/admin/
NSACL — This directory contains access control samples which implement the Loadable Attribute Service (LAS) APIs.
Directory path: install-dir/samples/nsacl
All of the sample applications are arranged in a specific and well-defined directory structure. In general, the top-level directory of a sample application includes the following:
src: A directory containing all the Java source files, deployment descriptors, JSPs, and HTML files. Samples that use a database provide a script to populate data in the database.
docs: A directory containing all documentation for the application.
.WAR file: The deployable .WAR file for the sample application.
build.xml: A file for the ANT system to build the sample application
A complete index of Java sample applications provided as part of the Sun Java System Web Server product is listed below:
Table 2–1 Java Samples
An ANT-based build system is used to build the individual sample application. The build.xml file has target to compile the sources, to clean, and to build the war file. It also has targets to deploy and undeploy the application, using the corresponding CLI commands provided by the Web Server. Register application resources in the deployment target.
Documentation is installed along with the samples during the installation. The index.html in the document root of the default Web Server instance contains links to the samples documentation. In addition, you can access the documentation HTML files directly in the samples directory.