Java web development using hibernate, jsp and servlets, 2007

Page 70

Web Development with Java

58

Load servlet , if not in memory

Create request and response objects from data sent from web server

Request Object

Response Object

Call doGet method with the request and response objects

Figure 2.20 Servlet engine handling a request for a servlet.

_ jspService method and it is up to the developer to recompile the .java file whenever it changes (Figure 2.20). The servlet engine will not automatically reload the .class file when it changes. It is up to the developer to reload the web application so that a servlet will be reloaded when it is requested the next time. Some servlet engines can be configured to automatically reload when a .class file changes, but it is not the default behaviour of the servlet engine.

2.3

Servlets in NetBeans

NetBeans is the perfect tool for developing web applications. After creating a web project, the web application can be run from within NetBeans by clicking on the Run -> Main Project menu. When this is done, Tomcat will be started, the servlet will be loaded into memory, a web browser will be opened and the default page for the web application will be displayed. Hypertext links can be added on this page that lead to the URLs of JSPs and servlets. After building a web project in NetBeans, it is possible to execute servlets from it. The servlets must be placed in the Source Packages folder. Always place servlets in packages. When the project is built, the source packages will be copied into the classes folder of the web application structure. Once a web project has been created and tested locally, it is a simple matter to upload the web application to a remote server. Every time that a web project is built, NetBeans packages all the files that are needed for a servlet engine into a Web Archive [WAR]. A WAR archive is a zip file containing all the files for the web application. If this is uploaded to a remote server, it can be deployed without making any modifications.

2.3.1

Source Packages

The Source Packages folder in a NetBeans project contains all the source files and packages for Java servlets. Place all source files in a package. All of the servlet


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.