How is a JSP page discovered and converted to Tomcat Servlet?

Is the JSP page detected only by the .jsp page extension? Is there any other way to detect it?

+4
source share
2 answers

Tomcat JSP pages are handled by a special servlet designed to handle all requests ending with .jsp or .jspx in an HTTP request. This configuration exists in the global file $CATALINA\conf\web.xml , where the following significant lines can be found. Please note that 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> 

Display JSP Servlet URL

 <!-- 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> 

Perhaps you can add more URL mappings for other file extensions that are not yet mapped to other servlets to run the Jasper compiler, which is ultimately responsible for translating the JSP files into the corresponding Java servlets, which are then compiled (using Eclipse JDT compiler by default). For more information on setting certain parameters in the process, see Tomcat's Jasper documentation .

+8
source

Here is a brief introduction from the section Servlet inline definitions 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 the JSP page discovery is done using the servlet mapping ( Embedded in the servlet mapping ) 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> 
+1
source

All Articles