What is Invoker Servlet:
Servlet Invoker is a mechanism which allows any servlet to be called by directly specifying the servlet class.
Its an implementation dependent feature i.e., every Web Container may have a different way of supporting this functionality.
The purpose of the Invoker Servlet is to allow a web application to dynamically register new servlet definitions that correspond with a <servlet> element in
the /WEB-INF/web.xml deployment descriptor, and execute requests utilizing the new servlet definitions.
From the perspective of the newly registered servlets, all servlet lifecycle requirements of the Servlet Specification.
It's highly discouraged to use this feature as it may result into a security breach.
By enabling this mechanism every servlet specified in the CLASSPATH of the Web Container can be directly called from outside.Please note for production environments the Servlet Invoker mechanism should never be used for calling servlets.
Servlet Mapping is a much better, robust, secure, and maintainable way of specifying which servlet to be called for an incoming URL. It makes the call transparent from the client's point of view. If we come up with a different version of the servlet (or if we want to change the servlet altogether) then we just need to modify the relevant entries in the Deployment Descriptor (web.xml). This change can be completely transparent to the clients as the URL may still the remain the same and the Web Container will simply call the modified servlet (or the newly specified servlet) for that URL.
Below is the syntax for enabling servlet invoker in tomcat 6:
Web.XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee">
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>client_prefix</param-name>
<param-value>DD</param-value>
</context-param>
<welcome-file>
index.jsp
</welcome-file>
<error-page>
<exception-type>org.krysalis.barcode4j.BarcodeException</exception-type>
<location>/errpg</location>
</error-page>
</web-app>
TOMCAT 7:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>client_prefix</param-name>
<param-value>DD</param-value>
</context-param>
<servlet>
<description></description>
<display-name>testServlet</display-name>
<servlet-name>testServlet</servlet-name>
<servlet-class>servletone.testServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/testServlet.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BarcodeServlet</servlet-name>
<servlet-class>org.krysalis.barcode4j.servlet.BarcodeServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BarcodeErrorServlet</servlet-name>
<servlet-class>org.krysalis.barcode4j.webapp.BarcodeErrorServlet</servlet-class>
</servlet>
<servlet>
<description></description>
<display-name>tstservlet</display-name>
<servlet-name>tstservlet</servlet-name>
<servlet-class>servlettwo.tstservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tstservlet</servlet-name>
<url-pattern>/tstservlet.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Servlet Invoker is a mechanism which allows any servlet to be called by directly specifying the servlet class.
Its an implementation dependent feature i.e., every Web Container may have a different way of supporting this functionality.
The purpose of the Invoker Servlet is to allow a web application to dynamically register new servlet definitions that correspond with a <servlet> element in
the /WEB-INF/web.xml deployment descriptor, and execute requests utilizing the new servlet definitions.
From the perspective of the newly registered servlets, all servlet lifecycle requirements of the Servlet Specification.
It's highly discouraged to use this feature as it may result into a security breach.
By enabling this mechanism every servlet specified in the CLASSPATH of the Web Container can be directly called from outside.Please note for production environments the Servlet Invoker mechanism should never be used for calling servlets.
Servlet Mapping is a much better, robust, secure, and maintainable way of specifying which servlet to be called for an incoming URL. It makes the call transparent from the client's point of view. If we come up with a different version of the servlet (or if we want to change the servlet altogether) then we just need to modify the relevant entries in the Deployment Descriptor (web.xml). This change can be completely transparent to the clients as the URL may still the remain the same and the Web Container will simply call the modified servlet (or the newly specified servlet) for that URL.
Below is the syntax for enabling servlet invoker in tomcat 6:
Web.XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee">
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>client_prefix</param-name>
<param-value>DD</param-value>
</context-param>
<welcome-file>
index.jsp
</welcome-file>
<error-page>
<exception-type>org.krysalis.barcode4j.BarcodeException</exception-type>
<location>/errpg</location>
</error-page>
</web-app>
TOMCAT 7:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>client_prefix</param-name>
<param-value>DD</param-value>
</context-param>
<servlet>
<description></description>
<display-name>testServlet</display-name>
<servlet-name>testServlet</servlet-name>
<servlet-class>servletone.testServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/testServlet.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BarcodeServlet</servlet-name>
<servlet-class>org.krysalis.barcode4j.servlet.BarcodeServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>BarcodeErrorServlet</servlet-name>
<servlet-class>org.krysalis.barcode4j.webapp.BarcodeErrorServlet</servlet-class>
</servlet>
<servlet>
<description></description>
<display-name>tstservlet</display-name>
<servlet-name>tstservlet</servlet-name>
<servlet-class>servlettwo.tstservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>tstservlet</servlet-name>
<url-pattern>/tstservlet.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
No comments:
Post a Comment