2011-05-05 72 views

回答

8

Tomcat中的JSP頁面由特定的Servlet處理,該Servlet旨在處理在HTTP請求中以.jsp.jspx終止的所有請求。該配置存在於全局文件$CATALINA\conf\web.xml中,其中可以找到以下重要行。請注意,是在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> 

你可能添加更多的URL映射不屬於其他文件擴展名已經映射到其他servlet,以觸發Jasper編譯器,最終負責將JSP文件轉換爲相應的Java servlet,whi然後編譯ch(默認情況下使用Eclipse JDT編譯器)。有關配置過程中某些選項的更多信息,請參見Tomcat documentation on configuring Jasper

+0

非常乾淨的插圖 – 2011-05-05 04:05:25

+0

謝謝,這使它真的很清楚! – pvsk10 2011-05-05 04:16:56

1

下面是從簡要介紹了內置在Servlet定義在$ 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". 

和JSP頁面檢測是通過servlet映射完成(內置在servlet映射節$ 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> 
相關問題