War&Servelets

WAR FILE AND SERVELETS

WAR DIAGRAMS

Slideshow 1:
Slideshow 2:

Audio file for this Document.
 
War File
A war (web archive) File contains files of a web project. It may have servlet, xml, jsp, image, html, css, js etc. files.
Here, we will discuss what is war file, how to create war file, how to deploy war file and how to extract war file.
________________________________________
What is war file?
web archive (war) file contains all the contents of a web application. It reduces the time duration for transferring file.
Advantage of war file
saves time: The war file combines all the files into a single unit. So it takes less time while transferring file from client to server.
________________________________________
How to create war file?
To create war file, you need to use jar tool of JDK. You need to use -c switch of jar, to create the war file.
Go inside the project directory of your project (outside the WEB-INF), then write the following command:

jar -cvf projectname.war *

Here, -c is used to create file, -v to generate the verbose output and -f to specify the arhive file name.
The * (asterisk) symbol signifies that all the files of this directory (including sub directory).
________________________________________
How to deploy the war file?
There are two ways to deploy the war file.
1. By server console panel
2. By manually having the war file in specific folder of server.


If you want to deploy the war file in apache tomcat server manually, go to the webapps directory of apache tomcat and paste the war file here.
Now, you are able to access the web project through browser.
Note: server will extract the war file internally.
________________________________________
How to extract war file manually?
To extract the war file, you need to use -x switch of jar tool of JDK. Let's see the command to extract the war file.
1. jar -xvf projectname.war
next>><<prev
welcome-file-list in web.xml
The welcome-file-list element of web-app, is used to define a list of welcome files. Its sub element is welcome-file that is used to define the welcome file.
A welcome file is the file that is invoked automatically by the server, if you don't specify any file name.
By default server looks for the welcome file in following order:
1. welcome-file-list in web.xml
2. index.html
3. index.htm
4. index.jsp
If none of these files are found, server renders 404 error.
   If you have specified welcome-file in web.xml, and all the files index.html, index.htm and index.jsp exists, priority goes to welcome-file.
If welcome-file-list entry doesn't exist in web.xml file, priority goes to index.html file then index.htm and at last index.jsp file.
Let's see the web.xml file that defines the welcome files.
web.xml
1. <web-app>
2. ....
3.
4.   <welcome-file-list>
5.    <welcome-file>home.html</welcome-file>
6.    <welcome-file>default.html</welcome-file>
7.   </welcome-file-list>
8. </web-app>
Now, home.html and default.html will be the welcome files.
If you have the welcome file, you can directory invoke the project as given below:
1. http://localhost:8888/myproject
As you can see, we have not specified any file name after the project.


Servlets | Servlet Tutorial

Servlet technology is used to create a web application (resides at server side and generates a dynamic web page).
Servlet technology is robust and scalable because of java language. Before Servlet, CGI (Common Gateway Interface) scripting language was common as a server-side programming language. However, there were many disadvantages to this technology. We have discussed these disadvantages below.
There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet, HttpServlet, ServletRequest, ServletResponse, etc.
What is a Servlet?
Servlet can be described in many ways, depending on the context.
o Servlet is a technology which is used to create a web application.
o Servlet is an API that provides many interfaces and classes including documentation.
o Servlet is an interface that must be implemented for creating any Servlet.
o Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests.
o Servlet is a web component that is deployed on the server to create a dynamic web page.
 
Do You Know?
o What is the web application and what is the difference between Get and Post request?
o What information is received by the web server if we request for a Servlet?
o How to run servlet in Eclipse, MyEclipse and Netbeans IDE?
o What are the ways for servlet collaboration and what is the difference between RequestDispatcher and sendRedirect() method?
o What is the difference between ServletConfig and ServletContext interface?
o How many ways can we maintain the state of a user? Which approach is mostly used in web development?
o How to count the total number of visitors and whole response time for a request using Filter?
o How to run servlet with annotation?
o How to create registration form using Servlet and Oracle database?
o How can we upload and download the file from the server?
What is a web application?
A web application is an application accessible from the web. A web application is composed of web components like Servlet, JSP, Filter, etc. and other elements such as HTML, CSS, and JavaScript. The web components typically execute in Web Server and respond to the HTTP request.
________________________________________
CGI (Common Gateway Interface)
CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request. For each request, it starts a new process.
 
Disadvantages of CGI
There are many problems in CGI technology:
1. If the number of clients increases, it takes more time for sending the response.
2. For each request, it starts a process, and the web server is limited to start processes.
3. It uses platform dependent language e.g. C, C++, perl.
________________________________________
Advantages of Servlet
 
There are many advantages of Servlet over CGI. The web container creates threads for handling the multiple requests to the Servlet. Threads have many benefits over the Processes such as they share a common memory area, lightweight, cost of communication between the threads are low. The advantages of Servlet are as follows:
1. Better performance: because it creates a thread for each request, not process.
2. Portability: because it uses Java language.
3. Robust: JVM manages Servlets, so we don't need to worry about the memory leak, garbage collection, etc.
4. Secure: because it uses java language.

Comments

Popular posts from this blog

Bsu

linux

Domain