DefaultServlet和JspServlet

DefaultServlet和JspServlet

摘自

Tomcat在$CATALINA_BASE/conf/web.xml中默认定义了两个Servlet: DefaultServlet和JspServlet

DefaultServlet








<servlet>
    <servlet-name>defaultservlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServletservlet-class>
    <init-param>
        <param-name>debugparam-name>
        <param-value>0param-value>
    init-param>
    <init-param>
        <param-name>listingsparam-name>
        <param-value>falseparam-value>
    init-param>
    <load-on-startup>1load-on-startup>
servlet>

<servlet-mapping>
    <servlet-name>defaultservlet-name>
    <url-pattern>/url-pattern>
servlet-mapping>

DefaultServlet主要用于处理静态资源文件,如HTML,图片,CSS,JS文件,还支持查看目录列表,只需要将名为listings的init-param设置为true

JspServlet





<servlet>
    <servlet-name>jspservlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServletservlet-class>
    <init-param>
        <param-name>forkparam-name>
        <param-value>falseparam-value>
    init-param>
    <init-param>
        <param-name>xpoweredByparam-name>
        <param-value>falseparam-value>
    init-param>
    <load-on-startup>3load-on-startup>
servlet>

<servlet-mapping>
    <servlet-name>jspservlet-name>
    <url-pattern>*.jspurl-pattern>
    <url-pattern>*.jspxurl-pattern>
servlet-mapping>

默认情况下,JspServlet的url-pattern为*.jsp,*.jspx,主要负责处理所有的JSP文件的请求

你可能感兴趣的:(tomcat)