因為web-inf下,應用伺服器把它指為禁訪目錄,即直接在浏覽器裡是不能通路到的。但是可以讓servlet進行通路,
如web-inf下有a.jsp則可以用request.getRequestDispatcher("/WEB-INF/a.jsp").forward(request,response);如果想通路web-inf下的html檔案的話,用request.getRequestDispatcher("/WEB-INF/a.html").forward(request,response);是通路不了的。原因很簡單,jsp就是servlet,會被編譯成class檔案,而html的就不行了。 是以需要配置以下conf下的web.xml檔案才能去通路html。
具體實作如下: 用打開tomcat安裝目錄下conf下的web.xml檔案,找到
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
然後在它下面添加
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
這樣的話,就能用request.getRequestDispatcher("/WEB-INF/a.html").forward(request,response);去通路web-inf下的html了