CSS font stacks & developer FAQs with Web standards

WestNIC provides reliable web hosting services

Fastwebhost offers cheap web hosting & reseller hosting services

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQ answers.

What if you were One Percent Better? Java ebooks for iPad, Kindle, Nook and Sony Reader

General container questions

Q: What's the difference between application servers and Web servers?

A: Web servers are primarily designed to deliver Web site content and not much besides. Application servers may include a Web server component, such as a Java servlet container, but manage it alongside other components, such as an Enterprise JavaBeans container, so that there is a shared execution context amongst them.

Examples of standard web servers include Apache httpd, Microsoft Internet Information Server (IIS), and Lighttpd, which primarily serve content using the HTTP protocol. Examples of Java Application servers include WebSphere Application Server from IBM, Oracle WebLogic Server and OC4J, JBoss, Apache Geronimo, Sun GlassFish Enterprise Server and SAP Netweaver.

Q: How can I write a servlet container using Java?

A: You are strongly recommended to join an existing servlet container project rather than write one yourself. A servlet container is an extremely complex system to create and most implementations have taken many years to develop to a robust, high performance standard. The Apache Tomcat container is an open source project that would be a good place to start.

Q: Is a JDK installation necessary to run JSP?

A: The latest version of the Apache Tomcat servlet container is designed to run only using the Java Runtime Environment (JRE), not a full Java Software Development Kit.

Q: Does the servlet run when the container starts up?

A: Servlet classes are not normally initialised when the servlet container is first started, they are brought into service when the first request for the servlet is received. Much of the time this "just in time" approach will not cause a significant delay. If a servlet has overridden the init(ServletConfig) method with a with a lengthy initialisation stage, the first user must wait for the method to return before the servlet handles their request.

Q: What happens if the server is not loaded into memory?

A: If the server or container object is not loaded in memory because it is shutting down or starting up, it will not be listening for requests and cannot accept connections. Any clients that attempt to connect to the server will normally fail after a client-specific timeout period.

Q: Is the session ID stored in the servlet or container?

A: When you first request a session through the HttpServletRequest object, the servlet container manages the creation and storage of a reference to the HttpSession object. If a subsequent request is received that corresponds with an existing session object, the HttpServletRequest getSession() method will return the session object created in the first request.

… full answer hidden

Premium members click below for full answer
Is the session ID stored in the servlet or container?

Web application configuration

Q: What is web.xml for?

A: The web.xml file contains configuration information for a single Web application. It includes configuration entries for each of the filters and servlets in the application, and a set of URL mappings for each. There is also a set of configuration entries that apply to every filter, servlet and JSP in the Web application context.

Context, filter and servlet configurations may contain a set of name and value pairs that are loaded by the servlet container when it starts up. The URL mappings tell the container which resources should be used to process incoming requests, and the configuration parameters are used to pass variables to those resources.

Q: What is a servlet URL mapping?

A: A servlet URL mapping is the second part of a servlet configuration in a Web application's web.xml file. The first part declares the servlet and gives it a name, the URL mapping tells the servlet container on which URL the servlet should operate, as below.

… full answer hidden

Premium members click below for full answer
What is a servlet URL mapping?

Q: Do I need a different web.xml for each server?

A: The /WEB-INF/web.xml configuration scheme is common to all servlet containers that conform to the Java Servlet Specification version 2.2 and later. Some servlet containers have supplementary configuration files to apply their own special features. You need a web.xml file for each Web application you create. There is also a web.xml file for the servlet container as a whole.

Q: How do I load a servlet at start-up?

A: To request a servlet is initialised when the container starts up, add the load-on-startup element to the web.xml file in your WEB-INF directory, as below. Any positive integer value will signal start up initialisation.

… full answer hidden

Premium members click below for full answer
How do I load a servlet at start-up?

Q: How can I create database connections for all servlets?

A: The standard way to preserve database connections between servlet requests is to use a connection pool that governs access to a number of live connections. The pool uses your primary database driver to create the connections in advance and makes pooled connections available through its own URL identifier. When the application closes a pooled connection it just returns to the pool.

A database connection pool can be created and managed directly by your servlet application, or obtained through the servlet container using the Java Naming and Directory Interface (JNDI). The Apache Commons DBCP project provides the database connection pooling service used by the Tomcat servlet container, but can also used independently from the container. Container managed connection pools must be accessed using the javax.sql.DataSource interface, as outlined in the Tomcat JNDI Datasource HOW-TO.

Apache JServ questions

Q: I can't compile any servlets and JServ doesn't work!

A: If your compiler is failing with missing javax package references, it is very likely your classpath does not include jsdk.jar, the Java Servlet Development Kit. You need to include a line like this in a backed up copy of your autoexec.bat file and reboot your computer:

SET CLASSPATH=%classpath%;c:\jsdk2.0\lib\jsdk.jar
          

You should use the path to your own installation of the JSDK archive. See the classpath section of Apache JServ on Windows 95 for further details.

Q: How do I configure custom error pages for JServ?

A: To configure the Apache JServ servlet engine to serve custom error pages in the servlet zone, the ErrorDocument directive must be declared in specific Location sections in the jserv.conf configuration file. The file references point to directories in the document path for the main HTTP server, as above:

<Location /servlets>
  ErrorDocument 400 /error-docs/400.shtml
  ErrorDocument 403 /error-docs/403.shtml
  ErrorDocument 404 /error-docs/404.shtml
  ErrorDocument 500 /error-docs/500.shtml
</Location>

<Location /servlet>
  ErrorDocument 400 /error-docs/400.shtml
  ErrorDocument 403 /error-docs/403.shtml
  ErrorDocument 404 /error-docs/404.shtml
  ErrorDocument 500 /error-docs/500.shtml
</Location>
      

Note, the servlet engine must be stopped and restarted to initiate these changes.

Home · Web fonts · Font stacks · FAQs · Java · CSS · Javascript · HTML · Site manager