How is a JSP page detected and converted to a Servlet by Tomcat?

前端 未结 2 1964
小蘑菇
小蘑菇 2021-01-05 18:14

Is a JSP page detected by the page extension of .jsp only? Is there any other way it can be detected?

2条回答
  •  春和景丽
    2021-01-05 18:40

    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

    
        jsp
        org.apache.jasper.servlet.JspServlet
        
            fork
            false
        
        
            xpoweredBy
            false
        
        3
    
    

    JSP Servlet URL mapping

    
    
        jsp
        *.jsp
    
    
    
        jsp
        *.jspx
    
    

    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.

提交回复
热议问题