World class Hard Drive Recovery and renowned raid recovery services

WestNIC provides reliable web 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 FAQs and more.

Subscribe to this FAQ: RSS news feed

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Premium Content: Follow this link for subscription information More details available to premium content service subscribers:
Is the session ID stored in the servlet or container?

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Premium Content: Follow this link for subscription information More details available to premium content service subscribers:
What is a servlet URL mapping?

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Premium Content: Follow this link for subscription information More details available to premium content service subscribers:
How do I load a servlet at start-up?

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Premium Content: Follow this link for subscription information More details available to premium content service subscribers:
How can I create database connections for all servlets?

Actions: Follow-up, clarify or correct this answer. Submit a new question.

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.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log