How to Create a Dynamic Web Application

Create Dynamic Web Applications

Create Dynamic Web Applications

In my earlier articles we have seen the Basics of web application also we have seen that server will not handle dynamic content, but to serve/ handle dynamic content we have servlet container or web container. To know more that read my Things which you don’t know about servlet container. Also in this article we will see How to Create a Dynamic Web Application and How to deploy it to a Tomcat Server

To start creating the Dynamic web Application, the following things are needed.

Create a Dynamic Web Application

Create a Dynamic Web Application

Create a Dynamic Web Application

Give Application Name and Click Next

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Check the “Generate web.xml” deployment descriptor and click Finish

Create a Dynamic Web Application - Learn From Examples - Learn From Examples

Create a Dynamic Web Application – Learn From Examples – Learn From Examples

Now the application will be created by the Specified name along with the web.xml file.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Web.xml

Web.xml file is an entry point for all the web application. Whenever the request comes, it will first come to web.xml file then only it will proceed further.


<?xml version=<em>"1.0"</em> encoding=<em>"UTF-8"</em>?>

<web-app xmlns:xsi=<em>"http://www.w3.org/2001/XMLSchema-instance"</em> xmlns=<em>"http://java.sun.com/xml/ns/javaee"</em> xsi:schemaLocation=<em>"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"</em> id=<em>"WebApp_ID"</em> version=<em>"3.0"</em>>

<display-name>HelloWebApplication</display-name>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

</web-app>

Web-app

Web-app is a root element for web.xml file, also if you see version attribute is says its version 3.0. From version 3, all xml configurations are available as annotation. We will see configure the xml file using annotation in our fore coming sessions.

Display-name

This tag specifies the name of the application which we have specified at the beginning of the application creation.

Welcome-file-list

By default it has created many welcome files list, so when we try to run the application, from top to bottom it will search for any one of the files and display it to the user.

Adding an application to a tomcat Server.

I have downloaded tomcat 7 portable and extracted in a directory. We will see how to add servers and how to deploy our application to our tomcat

Right Click on the server window are and go to New-> Server.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Select tomcat 7 server from Apache and click on next.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Add Our application by selecting it and click on Add, then click on Finish.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Now we could see the added server and the application has been deployed in to that server.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

If we want to see the port number or if you wants change the default port number and if you want to know in which location the application will be deployed. Just Double click the server and you could see like this.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Now I have changed the deployment location as below, so that I can easy see whether the changes have been properly deployed or not.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Now start the server by right clicking it as mentioned below.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

After restart my application has been deployed in the following location.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Check whether the server is started or not by using the below URL.

localhost:9080

here 9080 is the port number which I have configured.

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

Now let check our application by using the below URL

http://localhost:9080/HelloWebApplication/

Create a Dynamic Web Application - Learn From Examples

Create a Dynamic Web Application – Learn From Examples

This is because I have placed the index.html in WEB-INF directory , copy that and place it in Webcontent directory and see the output

Create a Dynamic Web Application 15

Leave a comment

Your email address will not be published. Required fields are marked *