如果網站允許使用者上傳檔案,通常會禁止上傳可執行檔(如jsp & jspx),
除了檢查副檔名外,也可在app的web.xml加上以下設定,讓jsp/jspx變成唯讀:
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>readonly</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DefaultServlet</servlet-name>
<url-pattern>/path/to/upload/*</url-pattern>
</servlet-mapping>
但像jspx一般也很少人會去寫,建議直接在tomcat/conf/web.xml禁用:
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<!--<url-pattern>*.jspx</url-pattern>-->
</servlet-mapping>