Is a JSP page detected by the page extension of .jsp only? Is there any other way it can be detected?
html. The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code. This code implements the corresponding dynamic behavior of the page.
A JSP container is responsible for converting the JSP page into a servlet (known as the JSP page implementation class ) and compiling the servlet. These two steps form the translation phase . The JSP container automatically initiates the translation phase for a page when the first request for the page is received.
Note: When a JSP is accessed through a web browser, Tomcat decides whether to transforms a JSP into its Java servlet version ( . java file) and then compiles the Java servlet (i.e., resulting in a . class file). We do not need to compile a JSP file.
JSP pages in Tomcat are handled by a specific servlet that is meant to handle all requests that terminate with .jsp
or .jspx
in the HTTP request. This configuration exists in the global $CATALINA\conf\web.xml
file where one can find the following significant lines. Note that is for Tomcat 6.
JSP Servlet registration
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
JSP Servlet URL mapping
<!-- The mapping for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
You could possibly add more URL mappings for other file extensions that are not already mapped to other servlets, in order to trigger the Jasper compiler, that is eventually responsible for translation of the JSP files into corresponding Java servlets, which are then compiled (using the Eclipse JDT compiler, by default). More information on configuring some of the options in the process can be obtained from the Tomcat documentation on configuring Jasper.
Here's a brief introduction from Built In Servlet Definitions section in $TOMCAT_HOME/conf/web.xml
The JSP page compiler and execution servlet, which is the mechanism
used by Tomcat to support JSP pages. Traditionally, this servlet
is mapped to the URL pattern "*.jsp".
And JSP page detection is done via servlet mapping (Built In Servlet Mappings section in $TOMCAT_HOME/conf/web.xml):
<!-- The mapping for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With