如何解决Vaadin : 在 Vaadin V14 webapp 中禁用图像文件夹列表
我重建了 vaadin webapp 并删除了所有 Spring 功能。 我的 web 应用现在是非 Spring 应用的 GreetService 入门下载。
该应用程序在 tomcat 9.0 应用程序服务器上运行,在 TOMCAT_HOME/conf/web.xml 中使用以下配置进行目录列表。
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
应用程序中没有其他 web.xml。
我在我的 Maven 项目的 src/main/webapp 文件夹中创建了一个图像、图标和测试文件夹。应用程序目录布局如下。
我按照亚历杭德罗的建议在其中两个文件夹中包含了一个空的 index.html,并在另一个文件夹中放入了一个简单的文本文件。
我使用生产配置文件将应用程序构建到一个 WAR 文件中。
所有这些看起来都很好,我的应用程序与以下 URL 完美配合。
但是,如果我浏览到图像文件夹或图标文件夹,我会得到内容列表。
我想停止该级别的任何文件夹的任何列表。我构建了默认的应用程序启动器并部署了它,我得到了上述行为。
然后我尝试引入以下带有@WebInitParam 的@WebServlet 注释,以将这个webappp 的列表设置为false。这也没有效果。
这是我的 AgentServlet 类的服务方法中日志记录的输出。
18-12:32:33.620 [https-jsse-nio-8443-exec-10] INFO o.v.e.AgentServlet.service - Request: Context Path = /myapp-nospring-1.0,Request URI = /myapp-nospring-1.0/sw.js,Request URL = https://wfd.sybernet.com:8443/myapp-nospring-1.0/sw.js,Servlet Context Path = /myapp-nospring-1.0,Servlet Context Name = null,Servlet Mapping = /*,Servlet Mapping Match Value = sw.js,Servlet Mapping Match Name = PATH
18-12:32:33.623 [https-jsse-nio-8443-exec-10] INFO o.v.e.AgentServlet.service - In AgentServlet ... service().. Listings
Setting = false
18-12:32:33.625 [https-jsse-nio-8443-exec-10] INFO o.v.e.AgentServlet.lambda$service$0 -
org.vaadin.example.AgentServlet:org.vaadin.example.AgentServlet
18-12:32:33.626 [https-jsse-nio-8443-exec-10] INFO o.v.e.AgentServlet.lambda$service$0 - default:org.apache.catalina.servlets.DefaultServlet
18-12:32:33.629 [https-jsse-nio-8443-exec-10] INFO o.v.e.AgentServlet.lambda$service$0 jsp:org.apache.jasper.servlet.JspServlet
18-12:32:33.684 [https-jsse-nio-8443-exec-10] DEBUG c.v.f.s.c.UidlWriter.createUidl - * Creating response to client
18-12:32:33.688 [https-jsse-nio-8443-exec-10] DEBUG c.v.f.s.BootstrapHandler.getInitialUidl - Initial UIDL: [object
Object]
注册了三个 servlet - 默认一个,jsp 一个和我的一个,这是我的 AgentServlet 类和注释。
我的问题是:-
-
默认情况下,Vaadin servlet 是否允许列出这些文件夹,即列表默认设置为“true”。使用 web init 参数将其设置为 false 似乎没有任何效果。
-
将文件夹放在 Vaadin 应用程序的 webapp 上下文文件夹中是否存在根本性错误,即在 http://appserver:port/vaadin-web-app/images 中。如果我使用 JSP 应用程序执行此操作,该应用程序将按照我的预期运行,并且不会列出文件夹内容。你得到一个 404 或者如果 index.html 在那里,它将被呈现。如有任何意见或建议,我将不胜感激。
@WebServlet(value = { "/*"},initParams= {@WebInitParam(name="listings",value="false")},asyncSupported =true) public class AgentServlet extends VaadinServlet { /** the logger. */ private static final Logger MLOGGER = LogManager.getLogger(AgentServlet.class); @Override protected void servletInitialized() throws ServletException { super.servletInitialized(); MLOGGER.info("In AgentServlet ... servletInitialized()"); } @Override protected void service(HttpServletRequest request,HttpServletResponse response) { MLOGGER.info("In AgentServlet ... service()"); MLOGGER.info("Request: Context Path = " + request.getContextPath() + "\n,Request URI = " + request.getRequestURI() + "\n,Request URL = " + request.getRequestURL() + "\n,Servlet Context Path = " + request.getServletContext().getContextPath() + "\n,Servlet Context Name = " + request.getServletContext().getServletContextName() + "\n,Servlet Mapping = " + request.getHttpServletMapping().getPattern() + "\n,Servlet Mapping Match Value = " + request.getHttpServletMapping().getMatchValue() + "\n,Servlet Mapping Match Name = " + request.getHttpServletMapping().getMappingMatch().name() ); String ListingsSetting = getServletConfig().getInitParameter("listings"); MLOGGER.info("In AgentServlet ... service().. Listings Setting = " + ListingsSetting); request.getServletContext().getServletRegistrations().forEach((key,value) -> MLOGGER.info(key + ":" + value.getClassName())); try { super.service(request,response); } catch (ServletException se) { MLOGGER.error("In AgentServlet ... service() caught Servlet Exception " + se.getMessage()); } catch (IOException ie) { MLOGGER.error("In AgentServlet ... service() caught IO Exception " + ie.getMessage()); }
} }
解决方法
您可以通过将 TOMCAT_HOME\conf\web.xml 文件中的以下值更改为 false
来禁用服务器的目录列表:
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
也许您也可以尝试在目录中添加一个空的 index.html 文件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。