Java-Business-Application/C2/Creating-a-Java-web-project/English

From Script | Spoken-Tutorial
Revision as of 17:19, 1 July 2013 by Arya Ratish (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of script: Creating a Java Web Project

Author: arya

Keywords: deployment descriptor, web project, context, video tutorial


Visual Cue
Narration
Slide 1 Welcome to the spoken-tutorial on Creating a Java Web Project.
Slide 2 In this tutorial we will learn :
  • To create a Java Web Project
  • About Deployment Descriptor
  • About web.xml file


Slide 3

Software Requirements

Here we are using
  • Ubuntu Version 12.04
  • Netbeans IDE 7.3
  • JDK 1.7


Slide 4

Prerequisites

To follow this tutorial you must have knowledge of
  • Core Java using Netbeans IDE and
  • HTML

If not, for relevant tutorials please visit our website.

Switch to Netbeans IDE Now, let us see how to create a simple Java Web Project using Netbeans IDE.


For this we will switch to Netbeans IDE.

Click on File -> New Project Click on File and then click on New Project.
A New Project window opens. A New Project window opens up.
Select Java Web among categories and Web Application among Projects. From the categories, choose Java Web and from Projects choose Web Application.
Click on Next. Then click on Next.
A New Web Application window opens. New Web Application window opens.
Type the Project Name as MyFirstProject. We will type the Project Name as MyFirstProject.
The Project Location will remain as it is. Let us keep the default Project Location, which is NetbeansProjects.
The Project Folder will remain same as it is. We will keep the Project Folder also as the default one.
The rest of the fields will be set their default values. All the remaining fields will be set at their default values.
Click on Next. Click on Next.
Select GlassFish server as the Web Server. Select GlassFish server as the Web Server.
Highlight the Context Path. Note that Context Path is MyFirstProject, which is the same name as our Project.


We will learn about this in detail.

Click on Next and then click on Finish. Click on Next and then click on Finish.
In the Projects tab, a web application named MyFirstProject has been created.
Click on the arrow pointing towards MyFirstProject. Click on the arrow pointing towards MyFirstProject.
Scroll through all the nodes. We can see several nodes here.
We are not concerned about all of these nodes right now.
First, we will learn about what is known as a Deployment Descriptor.
Slide 5 A web application’s deployment descriptor describes:


  • the classes, resources and configuration of the application and
  • how the web server uses them to serve web requests


Slide 6 * The web server receives a request for the application.
  • It uses deployment descriptor to map the URL of the request.
  • It maps the URL to the code that has to handle the request.

The deployment descriptor is a file named web.xml.

Scroll through the nodes. We are not able to find the web.xml file from the nodes available here.
Go to New -> File To locate it, at the top left of the IDE, click on File, and then on New File.
Click on Web. From the Categories, select Web.
Click on Standard Deployment Descriptor(web.xml). From the File Types, select Standard Deployment Descriptor(web.xml).
Click on Next. Then click on Next.
Click on Finish. Click on Finish.
Click on the Files tab on the left side of the IDE. Click on the Files tab on the left side of the IDE.
Highlight Web Pages, WEB-INF and web.xml. Note that web.xml is visible under the WEB-INF folder of the Web Pages node.
Click on the Source tab at the top. Click on the Source tab at the top of the Editor window.
Highlight the web.xml file. We can see the source code now.
Highlight the web.xml header. We have an xml header here.
Highlight web-app. We also have a web-app node.
Now, we shall try running the web-application.
Right click on MyFirstProject. To do so, right click on MyFirstProject.
Click on Clean and Build. Click on Clean and Build.


This will delete any previously compiled files and other build outputs.


It will also recompile the application.

Right click on MyFirstProject and click on Run. Again, right click on MyFirstProject and then click on Run.
Hover your mouse over the browser window and highlight HelloWorld! We see that a browser window opens up and displays the message Hello World!
This is because when we run the project, the web application renders the page shown.
Highlight the URL. Now, let’s have a look at the URL that rendered the page.
It is localhost colon 8080 slash MyFirstProject.
Switch to Netbeans and show index.jsp. It is the index.jsp that was rendered.
Hover your mouse over the browser window. So when we run MyFirstProject by default we get a JSP page that says HelloWorld!
Switch to Netbeans IDE. Let us come back to our IDE.
Highlight index.jsp. We can see that under the WEB-INF folder there is index dot jsp.
Double click on index.jsp Double click on index.jsp.
Hover your mouse over the source code. We can see the source code here.


It is a simple JSP page with HTML tags only.

The server provides index.jsp by default when we run the web application.
Recall that we had come across something called ContextPath earlier.


We had set the ContextPath as MyFirstProject itself.

Type localhost:8080 Now, in the URL type localhost colon 8080.
Hover your mouse over the home page. We see that the home page of Glassfish server is displayed.
This Glassfish server instance may have many applications running on it.
To access a particular application type that application name in the URL.
So,we must type the specific application that has been deployed on that instance.
Type MyFirstProject in the URL. So we will type MyFirstProject here.



Press Enter. Press Enter.
Show the index.jsp page. We can see that the index.jsp gets displayed on the browser.

<PAUSE>

Slide 6

Summary

Let us summarize.

In this tutorial we have learnt

  • To create a simple Java Web project
  • Execute the web project
  • and about the web.xml file


Slide 6


About slide

* Watch the video available at the following link
  • It summarizes the Spoken Tutorial project
  • If you do not have good bandwidth, you can download and watch it


Slide 7

About slide

The Spoken Tutorial Project Team
  • Conducts workshops using spoken tutorials
  • Gives certificates for those who pass an online test
  • For more details, please write to contact at spoken hyphen tutorial dot org


Slide 8

Acknowledgement

Spoken Tutorial Project is a part of the Talk to a Teacher project
  • It is supported by the National Mission on Education through ICT, MHRD, Government of India
  • More information on this Mission is available at


Slide 9

Contributor slide

The Library Management System has been contributed by a leading software MNC, through their Corporate Social Responsibility programme.


They have also validated the content for this spoken tutorial.


This is Arya Ratish from IIT Bombay signing off.


Thank you for joining.

Contributors and Content Editors

Arya Ratish