如何通过Tomcat检测JSP页面并将其转换为Servlet? [英] How is a JSP page detected and converted to a Servlet by Tomcat?

查看:502
本文介绍了如何通过Tomcat检测JSP页面并将其转换为Servlet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否仅通过.jsp的页面扩展名检测到JSP页面?有没有其他方法可以检测到?

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

推荐答案

Tomcat中的JSP页面由一个特定的servlet处理所有在HTTP请求中以 .jsp .jspx 结尾的请求。此配置存在于全局 $ CATALINA\conf\web.xml 文件中,其中可以找到以下重要行。请注意,这适用于Tomcat 6.

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注册

<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映射

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

您可以为尚未映射到其他servlet的其他文件扩展名添加更多URL映射,为了触发Jasper编译器,最终负责将JSP文件转换为相应的Java servlet,然后编译(默认情况下使用Eclipse JDT编译器)。有关配置过程中某些选项的更多信息,请参阅 Tomcat有关配置Jasper的文档

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.

这篇关于如何通过Tomcat检测JSP页面并将其转换为Servlet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆