Saturday, 10 December 2016

Apache-Tomcat Interview Questions And Answers

Q. Difference between apache and apache-tomcat server ?
Apache:
  •     Apache mostly serves static content by itself, but there are many add-on modules (some of     which come with Apache itself) that let it modify the content and also serve dynamic content written in Perl, PHP, Python, Ruby, or other languages.
  •     Basically Apache is an HTTP Server, serving HTTP.

Apache-Tomcat:
  •     Tomcat is primarily a servlet/JSP container. Its written in Java. It can serve static content too, but its main purpose is to host servlets and JSPs.
  •     JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.
  •     Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.
  •     Although it is possible to get Tomcat to run Perl scripts and the like, you wouldn't use Tomcat unless most of your content was Java.
  •     Tomcat is a Servlet and JSP Server serving Java technologies

Note:
    The two technologies can be used together through a connector module called mod_jk. This will allow you to use the Apache HTTP server to serve regular static webpages, and the Tomcat Servlet engine to execute servlets.
   
Q. Difference between web server and application server ?
    1. Application Server supports distributed transaction and EJB.
        While Web Server only supports Servlets and JSP.
    2. Application Server can contain web server in them. most of App server e.g. JBoss or WAS has
        Servlet and JSP container.
    3. Though its not limited to Application Server but they used to provide services like Connection
        pooling, Transaction management, messaging, clustering, load balancing and persistence. Now
        Apache tomcat also provides connection pooling.
    4. In terms of logical difference between web server and application server. web server is supposed
        to provide http protocol level service
        while application server provides support to web service and expose business level service
        e.g. EJB.
    5. Application server are more heavy than web server in terms of resource utilization.

Q. How to start and shutdown to tomcat server
   There are two .sh file in cd $CATALINA_HOME/bin  dir or in /usr/share/tomcat7/bin/
    ./startup.sh
    ./shutdown.sh

Q. After startup what is the url for default web-application?
      http://localhost:8080/

Q. What are the directories under the apache-tomcat installation dir ?
  •     conf - Server configuration files (including server.xml)
  •     logs - Log and output files
  •     shared - For classes and resources that must be shared across all web applications
  •     webapps - Automatically loaded web applications
  •     work - Temporary working directories for web applications
  •     temp - Directory used by the JVM for temporary files (java.io.tmpdir)

Q. How to change the default(8080) port number?
  •     Go to tomcat>conf folder.
  •     Edit server.xml. (/usr/share/tomcat/conf/server.xml)
  •     Search "Connector port"
  •     Replace "8080" by your port number.
  •     Restart tomcat server.
  •    
    For example, if you change the port to 1977, you would request the URL http://localhost:1977/
   
    Note: While changing the port number make sure that port is not already in use and port no should be greater than 1024, as ports less than or equal to 1024 require superuser access to bind to.
  
Q. How to know your Apache tomcat version ?
    root@ubuntu:~# /usr/share/tomcat7/bin/version.sh
    Using CATALINA_BASE:   /usr/share/tomcat7
    Using CATALINA_HOME:   /usr/share/tomcat7
    Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
    Using JRE_HOME:        /usr/lib/jvm/java-1.7.0-openjdk-i386
    Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
    Server version: Apache Tomcat/7.0.26
    Server built:   Apr 1 2013 08:32:04
    Server number:  7.0.26.0
    OS Name:        Linux
    OS Version:     3.2.0-105-generic-pae
    Architecture:   i386
    JVM Version:    1.7.0_101-b00
    JVM Vendor:     Oracle Corporation

Q. what are the configuratiopn file in tomcat server?
    Tomacat XML Configuration Files:
  1.     server.xml(TOMCAT-HOME/conf/server.xml)
  2.     web.xml   (TOMCAT-HOME/conf/web.xml)    
  3.     tomcat-users.xml (TOMCAT-HOME/conf/tomcat-users.xml)
Q. How to use tomcat server as a HTTP server ?
    Tomcat also contains a HTTP connector which can be used to serve static HTML pages. The standard directory which will be served is below the Tomcat webapps/ROOT installation directory. Place static content into this directory.

    To allow directory browsing via Apache Tomcat change the listings parameter in the file conf/web.xml from false to true.
    <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
   
Q. Explain what is Jasper?
    Jasper is a Tomcat’s JSP engine
    It parses JSP files to compile them into JAVA code as servlets
    At run-time, Jasper allows to automatically detect JSP file changes and recompile them
   
Q. Where can be set roles,username and password ?
   /conf/tomcat-users.xml
  
   <tomcat-users>
        <role rolename="manager-gui" />
        <user username="tomcat" password="s3cret" roles="manager-gui" />
   </tomcat-users>

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...