Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

This will help in learning web development through servlets and JSP

Authors

Getting Started with Web applications development with servlets and JSP

Getting Started with Web applications development with servlets and JSP - Part 1: Setting Up Web Project

Apr 19 2012 12:00AM by Vladimir Djurovic   

Getting started: Setting Up Web Project

This series of posts will describe creation of web applications with Java language, using servlets and JSP (Java Server Pages). We will assume that user has basic knowledge of Java and Java SE libraries.

Servlets represent small Java programs which run on server and handle HTTP requests from clients. These are in some way similar to CGI scripts, i.e. they provide some sort of business logic which can be applied to a specific request. The advantage is that they are much simpler to implement and offer consistent API.

Java Server Pages are kind of dynamic HTML pages which can be used to display dynamic content. They provide custom expression language and variables to facilitate data representation.

Creating project with Maven

The first thing to do is to set up the project. We will use Maven as a build tool for this project, so we will use Maven archetype to create skeleton for our project (Maven installation instructions can be found here).

To begin, simply type the following command into console:

mvn archetype:generate

You will be presented with list of available archetypes. Choose maven-archetype-webapp and then simply enter required information into console. Maven will create standard Maven project structure.

Project Structure Description

Maven will create a directory structure for Java web application project. This is the standard Maven project hierarchy, which we will not discuss here (for more information on Maven refer to http://maven.apache.org). Instead, we will focus on src/main/webapp directory, which contains the files required for Java web application deployment. The image below shows contents of webapp directory:

Project Structure

WEB-INF directory is expected to appear in each web application. It contains the files needed for application at runtime, and also contains deployment descriptor file (web.xml). During application build, two new directories will be created inside WEB-INF: lib and classes. Directory classes will contain compiled java code for the application, while lib contains all dependencies (ie. Classpath).

The web.xml file is called deployment descriptor, and is vital part of the web application. It contains data needed by application server to correctly deploy and start the application. This file must always be called web.xml and its content is defined by Java servlet specification.

Finally, index.jsp is the welcome file, ie. the file shown by default when user enters application URL without specific page (eg. http://localhost:8080/samplewebapp). This is JSP file that is generated by Maven, and contains a simple “Hello, world” message.

Now, to try out the application, simply run the following command:

mvn tomcat:run

This will start Tomcat server on default port 8080. To test the application, enter the following URL into your browser:

http://localhost:8080/samplewebapp

You should get the following result:

Hello World

Application Deployment Details

As mentioned above, the most important file is web.xml, which contains application deployment information. The Maven-generated file is quite simple, and its content is shown here:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>

This deployment descriptor contains only one information, application display name. This is the name shown in server's administration console.

We will go into more details of deployment descriptor in the following chapters. For now, this will suffice.

One other thing to note is the context path. Context path is the part of URL after server and port, i.e. samplewebapp in this case. Each Java web application must have it's own unique context path. In Maven, default context path is application name. This can be overriden by specifying custom server settings, but it is out of scope of this tutorial. For more information about this, refer to Tomcat web site (http://tomcat.apache.org)

In the next chapter, we will create our first servlet.

Find the sample web application here.


Vladimir Djurovic
78 · 2% · 717
7 Readers Liked this
Jacob Sebastian Liked this on 4/19/2012 1:41:00 AM
Profile · Blog · Facebook · Twitter
Neha Mewara Liked this on 4/19/2012 1:41:00 AM
Profile
Guru Samy Liked this on 4/19/2012 5:47:00 AM
Profile · Blog
Khyati Patel Liked this on 4/20/2012 1:38:00 AM
Profile · Facebook · Twitter
sukhan Liked this on 4/20/2012 8:24:00 AM
Profile
Manas Ranjan Dash Liked this on 4/23/2012 10:21:00 PM
Profile · Blog · Facebook · Twitter
Ramireddy Liked this on 6/4/2012 5:41:00 AM
Profile · Facebook · Twitter
7
Liked



Submit

Your Comment


Sign Up or Login to post a comment.

"Getting Started with Web applications development with servlets and JSP - Part 1: Setting Up Web Project" rated 5 out of 5 by 7 readers
Getting Started with Web applications development with servlets and JSP - Part 1: Setting Up Web Project , 5.0 out of 5 based on 7 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]