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
Give Application Name and Click Next
Check the “Generate web.xml” deployment descriptor and click Finish
Now the application will be created by the Specified name along with the web.xml file.
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 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.
This tag specifies the name of the application which we have specified at the beginning of the application creation.
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.
Select tomcat 7 server from Apache and click on next.
Add Our application by selecting it and click on Add, then click on Finish.
Now we could see the added server and the application has been deployed in to that server.
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.
Now I have changed the deployment location as below, so that I can easy see whether the changes have been properly deployed or not.
Now start the server by right clicking it as mentioned below.
After restart my application has been deployed in the following location.
Check whether the server is started or not by using the below URL.
here 9080 is the port number which I have configured.
Now let check our application by using the below URL
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