Chapter 7: Web Application Confi guration By arbitrary,

Chapter 7: Web Application Confi guration By arbitrary, we do not mean that they can be placed anywhere and the server will find them. Rather, as long as the files are put within the Web application directory, and outside of the WEB-INF directory, then the application itself (and its designer) decides where files are placed. In the example Web application shown in Figure 7-1 , index.jspis the default welcome page for the Web application. The welcome page is the Web page served up when you access the Web application URL in this case, http://localhost:8080/exampleapp/. If this Web page were not present, then, by default, index.htmland index.htm are looked for and served. These welcome pages are subject to configuration and can be modified, as you will see later in the chapter. Besides index.jspand contact.html, the other public resources in the example application are the image files in the imagesdirectory. URL Mappings In most cases, when you request a Web resource from your browser (such as an HTML page), it is served to you without modification by the Web server. JSP pages are an exception to this. A JSP page is first passed through a JSP compiler that compiles the file to a Java file, and then compiles the Java file to a Servlet class. This Servlet class then executes, and the output is displayed on your browser. The code that makes this happen is a URL mapping defined using a element, as shown next. This URL mapping is defined in /conf/web.xml. This file is the deployment descriptor for all the Web applications individual Web applications can define their own deployment descriptors. jsp *.jsp The preceding code specifies that any URL that ends in .jspshould be passed to a servlet named jsp that is defined elsewhere in the same /conf/web.xmlconfiguration file. The definition for this servlet is as follows: jsp org.apache.jasper.servlet.JspServlet3 As you can see, the fully qualified name of the servlet is org.apache.jasper.servlet.JspServlet. The servlet is handed the request, uses the context path to load the JSP page, and passes it to Tomcat s JSP compiler, known as Jasper. The load-on-startup option ensures that the Servlet class is loaded into memory on startup with a priority of 3 (where 1 is most important) to ensure that it is loaded before any JSP pages are requested. You ll see other configuration options in the web.xml, too, and these are explained in greater detail later in this chapter.

For high quality java hosting services please check java web hosting website.

Comments are closed.