因为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文件,找到 内容,
然后在它下面添加内容,最后如下
<!-- The mappings for the JSP servlet --> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.jspx</url-pattern> <url-pattern>*.html</url-pattern> </servlet-mapping>
如果没生效的话就别勉强了,一般只有jsp文件才放在web-inf下面