今天看一个同事的web框架,web.xml的配置如下:
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>4</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.aspx</url-pattern> </servlet-mapping> <servlet> <servlet-name>api</servlet-name> <servlet-class>com.xxxxi.http.ApiServlet</servlet-class> <init-param> <param-name>executor_name</param-name> <param-value>apiExecutor</param-value> </init-param> <load-on-startup>4</load-on-startup> </servlet> <servlet-mapping> <servlet-name>api</servlet-name> <url-pattern>/api</url-pattern> </servlet-mapping>
?发现其中没有配置类似:*.jsp的访问格式也能够访问jsp页面,很是疑惑。找那个同事问了一下:原来tomcat的默认配置文件中有这个配置项:
?
查看tomcat的conf目录下web.xml文件,中间有一段:
<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> ………… <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> …………
?
原来tomcat中默认配置了*.jsp的servlet访问映射。因此此处可以省略配置。很多东西还是不清楚,要多像周围的人学习啊。