Servlet interview questions
1.What are Servlets?
2.What are advantages of servlets over CGI?
3.Can you explain Servlet life cycle?
4.What are the two important API’s in for Servlets?
5.Can you explain in detail “javax.servlet” package?
6.What’s the use of ServletContext?
7.How do we define an application level scope for servlet?
8.What’s the difference between GenericServlet and HttpServlet?
9.Can you explain in detail javax.servlet.http package?
10.What’s the architecture of a Servlet package?
11.Why is HTTP protocol called as a stateless protocol?
12.What are the different ways we can maintain state between requests?
13.What is URL rewriting?
14.What are cookies?
15.What are sessions in Servlets?
16.What’s the difference between getSession(true) and getSession(false) ?
17.What’s the difference between “doPost” and “doGet” methods?
18.Which are the different ways you can communicate between servlets?
19.What is functionality of “RequestDispatcher” object?
20.How do we share data using “getServletContext ()”?
21.Explain the concept of SSI?
22.What are filters in JAVA?
23.Can you explain in short how do you go about implementing filters using Apache Tomcat?
24.what’s the difference between Authentication and authorization?
Showing posts with label servelets. Show all posts
Showing posts with label servelets. Show all posts
Servlet mapping Interview Questions
Servlet mapping Interview
What is servlet mapping?
Servlet mapping specifies the web container of which java servlet should be invoked for a url given by client. It maps url patterns to servlets. When there is a request from a client, servlet container decides to which application it should forward to. Then context path of url is matched for mapping servlets.
How is servlet mapping defined?
Servlets should be registered with servlet container. For that, you should add entries in web deployment descriptor web.xml. It is located in WEB-INF directory of the web application.
Entries to be done in web.xml for servlet-mapping:
servlet-mapping has two child tags, url-pattern and servlet-name. url-pattern specifies the type of urls for which, the servlet given in servlet-name should be called. Be aware that, the container will use case-sensitive for string comparisons for servlet matching.
Syntax for servlet mapping as per servlet specification SRV.11.2:
A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
A string beginning with a ‘*.’ prefix is used as an extension mapping.
A string containing only the ‘/’ character indicates the “default” servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
All other strings are used for exact matches only.
Rule for URL path mapping:
It is used in the following order. First successful match is used with no further attempts.
1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the ’/’ character as a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a “default” servlet is defined for the application, it will be used.
What is implicit mapping?
A servlet container can have a internal JSP container. In such case, *.jsp extension is mapped to the internal container. This mapping is called implicit mapping. This implicit mapping allows ondemand execution of JSP pages. Servlt mapping defined in web application has high precedence over the implicit mapping.
What is Servlet Invoker?
As defined by Apache Tomcat specification, the purpose of Invoker Servlet is to allow a web application to dynamically register new servlet definitions that correspond with aelement in the /WEB-INF/web.xml deployment descriptor.By enabling servlet invoker the servlet mapping need not be specified for servlets. Servlet ‘invoker’ is used to dispatch servlets by class name.
Enabling the servlet invoker can create a security hole in web application. Because, Any servlet in classpath even also inside a .jar could be invoked directly. The application will also become not portable. Still if you want to enable the servlet invoker consult the web server documentation, because every server has a different method to do it.
In Tomcat 3.x, by default the servlet invoker is enabled. Just place the servlets inside /servlet/ directory and access it by using a fully qualified name like http://[domain]:[port]/[context]/servlet/[servlet.
This mapping is available in web application descriptor (web.xml), located under $TOMCAT_HOME/conf.
/servlet/ is removed from Servlet 2.3 specifications.
In Tomcat 4.x, by defaul the servlet invoker id disabled. Thetag is commented inside the default web application descriptor (web.xml), located under $CATALINA_HOME/conf. To enable the invoker servlet uncomment the following two blocks.
What is servlet mapping?
Servlet mapping specifies the web container of which java servlet should be invoked for a url given by client. It maps url patterns to servlets. When there is a request from a client, servlet container decides to which application it should forward to. Then context path of url is matched for mapping servlets.
How is servlet mapping defined?
Servlets should be registered with servlet container. For that, you should add entries in web deployment descriptor web.xml. It is located in WEB-INF directory of the web application.
Entries to be done in web.xml for servlet-mapping:
servlet-mapping has two child tags, url-pattern and servlet-name. url-pattern specifies the type of urls for which, the servlet given in servlet-name should be called. Be aware that, the container will use case-sensitive for string comparisons for servlet matching.
Syntax for servlet mapping as per servlet specification SRV.11.2:
A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
A string beginning with a ‘*.’ prefix is used as an extension mapping.
A string containing only the ‘/’ character indicates the “default” servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.
All other strings are used for exact matches only.
Rule for URL path mapping:
It is used in the following order. First successful match is used with no further attempts.
1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the ’/’ character as a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last ’.’ character.
4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a “default” servlet is defined for the application, it will be used.
What is implicit mapping?
A servlet container can have a internal JSP container. In such case, *.jsp extension is mapped to the internal container. This mapping is called implicit mapping. This implicit mapping allows ondemand execution of JSP pages. Servlt mapping defined in web application has high precedence over the implicit mapping.
What is Servlet Invoker?
As defined by Apache Tomcat specification, the purpose of Invoker Servlet is to allow a web application to dynamically register new servlet definitions that correspond with a
Enabling the servlet invoker can create a security hole in web application. Because, Any servlet in classpath even also inside a .jar could be invoked directly. The application will also become not portable. Still if you want to enable the servlet invoker consult the web server documentation, because every server has a different method to do it.
In Tomcat 3.x, by default the servlet invoker is enabled. Just place the servlets inside /servlet/ directory and access it by using a fully qualified name like http://[domain]:[port]/[context]/servlet/[servlet.
This mapping is available in web application descriptor (web.xml), located under $TOMCAT_HOME/conf.
/servlet/ is removed from Servlet 2.3 specifications.
In Tomcat 4.x, by defaul the servlet invoker id disabled. The
Servlets Interview Questions
Servlets Interview Questions
1) Explain in detail about a servlet?
A Java servlet can be thought as an Applet but this runs on the server without the front side. This is used in applications where there is need for functionality of the web server and it is also used to access the existing business applications. It removes the limitations caused due to CGI. Servlet is platform and server independent which makes it much more popular to use.
2) State some of the uses of Java servlet?
Java servlet is used for many purposes. Being platform and server independent it is used for wide variety of purposes. They can provide secured access to web based data. Type safety and RAD based features help in productivity. It can be used to extend the functionality present in web servers.
3) What services can be obtained by implementing Java Servlets?
These are the following services which can be obtained by using Java servlets they are: -
• Multi user services can be provided by organization using Java servlets to their clients.
• They can also serve static web pages by making use of HTTP/ (s) protocols.
• Search engines and semi custom applications can make use of servlets (web based entry, etc).
4) Should the user or client be in the same software language in their applications?
Servlets are programmed in Java and the user need not be in the same language to access or implement the features of Servlets. They are used in middle tier which provides them a flexibility to be clients for other applications and the client who is accessing the servlet need not have the same language as the servlet.
5) Is load balancing possible with a servlet?
Load balancing is possible with the use of servlets. A servlet can forward requests to other servers which can drastically reduce load. This technique can reduce load by mirroring the same content among several servers. A single logical service can be partitioned among several servers i.e., routing according to task type.
6) Explain about the service method?
Request and Response parameters are provided with the service methods. These parameters implement encapsulation; they also give access to parameters which allows them to report errors and status reports. Contrarily servlets retrieve parameters through an input stream and responses are sent through output stream.
7) Explain about the different usage modes present in Java servlet?
Servlets can be used in many different modes they are: -
1) Filter chains can be used to chain servlets together.
2) They can be used to support HTTP protocols.
3) They are the best replacement for CGI based applications
4) Dynamic generation of content is possible with Servlets.
8) State the different ways of loading a servlet?
The different ways in which a servlet can be loaded are as follows: -
1) Dynamic loading of servlet is always possible.
2) Servers do provide an administrative option through which force loading and initialization is possible.
3) Servlets can also be loaded by Java class; they can be loaded from remote directories and local file systems.
9) Explain about servlet container?
Servlet container supports servlet execution. Basic functionality of a web server and IDE of Java can be used for better performance. Specific URL`s can be translated into servlet requests. Individual servlets get them selves registered with the container and this container holds and provides information about the functionality of the servlet and the Url which can access the servlet.
10) Explain about servletConfig and servletContext in applications?
Servletcontext is used to obtain application level information and only one servletcontext can be present in one application. ServletConfig object is present for every servlet and it provides initialization parameters for every servlet.
11) Explain about Http specific servlets?
Servlets using Http protocol support Http methods which includes GET, HEAD, POST, etc. Request and response data are always provided in an MIME format. Data type is specified by the servlet and data is also written in that format which gives greater flexibility in sending output in the format requested.
12) Explain about performance features of servlets?
Creation of a new process for each and every request can be avoided and this is deemed to be the biggest performance feature of servlets. Servlets run in parallel and in hand with the same process in the server. It provides greater flexibility and performance over CGI and fast CGI in an HTTP environment.
13) Explain about JVM and Java servlets?
Java servlets give greater performance for leveraging Java and related internet technologies. Throughput and response time can be improved by using Java servlets. With help from JVM Java servlet programs take advantage of additional processors which will help them scale up operations from entry level servers to main frame level applications.
14) How does servlets handle data and give some examples of this feature?
Servlets with precoded logic process data and they return reports in an appropriate format. Some of the examples of such formats are historical graphs and tables, web data, automated forecasts, etc. Administrative data such as addition, deletion of data can be performed with Servlets.
15) What are the two different kinds of servlets used by collecting sites?
There are two kinds of servlets used by collecting sites they are used to push and pull data. One kind of servlet is used to push data to the collecting site and the other is used to pull data from the appropriate format. These formats can be clubbed with other servlets which further aggregate data and can be used for large engineering projects.
16) What are the various different input parameters which servlets accept?
There are various different iinput parameters which servlets accept they are
1) Request or an input stream from an applet or so.
2) Request of the URL
3) From different servlets or networks.
4) Parameters passed from an HTML form.
17) Explain about the security features of Servlets?
Servlets cannot be trusted they have information about the clients. They have access to HTTP specific authentication data and peer identities can be determined. Strong security policy support is present in Java servlets. Access to network files and services needs to be restricted for a servlet. Security manager provided by Java can be used to control the level of security.
1) Explain in detail about a servlet?
A Java servlet can be thought as an Applet but this runs on the server without the front side. This is used in applications where there is need for functionality of the web server and it is also used to access the existing business applications. It removes the limitations caused due to CGI. Servlet is platform and server independent which makes it much more popular to use.
2) State some of the uses of Java servlet?
Java servlet is used for many purposes. Being platform and server independent it is used for wide variety of purposes. They can provide secured access to web based data. Type safety and RAD based features help in productivity. It can be used to extend the functionality present in web servers.
3) What services can be obtained by implementing Java Servlets?
These are the following services which can be obtained by using Java servlets they are: -
• Multi user services can be provided by organization using Java servlets to their clients.
• They can also serve static web pages by making use of HTTP/ (s) protocols.
• Search engines and semi custom applications can make use of servlets (web based entry, etc).
4) Should the user or client be in the same software language in their applications?
Servlets are programmed in Java and the user need not be in the same language to access or implement the features of Servlets. They are used in middle tier which provides them a flexibility to be clients for other applications and the client who is accessing the servlet need not have the same language as the servlet.
5) Is load balancing possible with a servlet?
Load balancing is possible with the use of servlets. A servlet can forward requests to other servers which can drastically reduce load. This technique can reduce load by mirroring the same content among several servers. A single logical service can be partitioned among several servers i.e., routing according to task type.
6) Explain about the service method?
Request and Response parameters are provided with the service methods. These parameters implement encapsulation; they also give access to parameters which allows them to report errors and status reports. Contrarily servlets retrieve parameters through an input stream and responses are sent through output stream.
7) Explain about the different usage modes present in Java servlet?
Servlets can be used in many different modes they are: -
1) Filter chains can be used to chain servlets together.
2) They can be used to support HTTP protocols.
3) They are the best replacement for CGI based applications
4) Dynamic generation of content is possible with Servlets.
8) State the different ways of loading a servlet?
The different ways in which a servlet can be loaded are as follows: -
1) Dynamic loading of servlet is always possible.
2) Servers do provide an administrative option through which force loading and initialization is possible.
3) Servlets can also be loaded by Java class; they can be loaded from remote directories and local file systems.
9) Explain about servlet container?
Servlet container supports servlet execution. Basic functionality of a web server and IDE of Java can be used for better performance. Specific URL`s can be translated into servlet requests. Individual servlets get them selves registered with the container and this container holds and provides information about the functionality of the servlet and the Url which can access the servlet.
10) Explain about servletConfig and servletContext in applications?
Servletcontext is used to obtain application level information and only one servletcontext can be present in one application. ServletConfig object is present for every servlet and it provides initialization parameters for every servlet.
11) Explain about Http specific servlets?
Servlets using Http protocol support Http methods which includes GET, HEAD, POST, etc. Request and response data are always provided in an MIME format. Data type is specified by the servlet and data is also written in that format which gives greater flexibility in sending output in the format requested.
12) Explain about performance features of servlets?
Creation of a new process for each and every request can be avoided and this is deemed to be the biggest performance feature of servlets. Servlets run in parallel and in hand with the same process in the server. It provides greater flexibility and performance over CGI and fast CGI in an HTTP environment.
13) Explain about JVM and Java servlets?
Java servlets give greater performance for leveraging Java and related internet technologies. Throughput and response time can be improved by using Java servlets. With help from JVM Java servlet programs take advantage of additional processors which will help them scale up operations from entry level servers to main frame level applications.
14) How does servlets handle data and give some examples of this feature?
Servlets with precoded logic process data and they return reports in an appropriate format. Some of the examples of such formats are historical graphs and tables, web data, automated forecasts, etc. Administrative data such as addition, deletion of data can be performed with Servlets.
15) What are the two different kinds of servlets used by collecting sites?
There are two kinds of servlets used by collecting sites they are used to push and pull data. One kind of servlet is used to push data to the collecting site and the other is used to pull data from the appropriate format. These formats can be clubbed with other servlets which further aggregate data and can be used for large engineering projects.
16) What are the various different input parameters which servlets accept?
There are various different iinput parameters which servlets accept they are
1) Request or an input stream from an applet or so.
2) Request of the URL
3) From different servlets or networks.
4) Parameters passed from an HTML form.
17) Explain about the security features of Servlets?
Servlets cannot be trusted they have information about the clients. They have access to HTTP specific authentication data and peer identities can be determined. Strong security policy support is present in Java servlets. Access to network files and services needs to be restricted for a servlet. Security manager provided by Java can be used to control the level of security.
Subscribe to:
Posts (Atom)