What is the difference between application server and web server?
The main difference between Web server and application server is that web server is meant to serve static pages e.g. HTML and CSS, while Application Server is responsible for generating dynamic content by executing server side code e.g. JSP, Servlet or EJB.
Which one should i use?
Once you know the difference between web and application server and web containers, it's easy to figure out when to use them.
You need a web server
like Apache HTTPD if you are serving static web pages. If you have a Java application with just JSP and Servlet to generate dynamic content then you need web containers
like Tomcat or Jetty. While, if you have Java EE application using EJB, distributed transaction, messaging and other fancy features than you need a full fledged application server
like JBoss, WebSphere or Oracle's WebLogic.
Web container is a part of Web Server and the Web Server is a part of Application Server.
Web Server is composed of web container, while Application Server is composed of web container as well as EJB container.