当前位置: 首页 > 知识库问答 >
问题:

Vaadin:禁用Vaadin V14 webapp中的图像文件夹列表

周奇文
2023-03-14

我已经重建了vaadin webapp,并删除了任何Spring功能。我的网络应用程序现在是非基于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。

我包括一个空的index.html在两个文件夹亚历杭德罗建议,只是把一个简单的文本文件在另一个。

我使用生产配置文件将应用程序构建成WAR文件。

所有这些看起来都很好,我的应用程序与以下URL完美配合。

但是,如果我浏览到images文件夹或icons文件夹,我会得到一个内容列表。

我想停止该级别的任何文件夹列表。我构建并部署了默认的应用程序启动程序,并获得了上述行为。

然后,我尝试使用@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-网络应用/图片。如果使用JSP应用程序执行此操作,则应用程序的行为将与我预期的一样,并且不会列出文件夹内容。你会得到一个404或如果索引。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());
     }
    

    } }

  • 共有1个答案

    公冶浩慨
    2023-03-14

    您可以通过在TOMCAT_HOME\conf\web中将以下值更改为false来禁用服务器的目录列表。xml文件:

    <init-param>
           <param-name>listings</param-name>
           <param-value>true</param-value>
    </init-param>
    

    也许您还可以尝试添加一个空索引。将html文件复制到目录中。

     类似资料:
    • 我可以上传图片在数据库,但不能上传到“文件”文件夹。万维网 这是图像上传servlet。一旦图像被上传,它就应该被插入到files文件夹中。我不知道我犯了什么错误。谁能告诉我出了什么问题吗?我需要添加上传目录或文件路径C:inside吗?

    • 我正在尝试访问src文件夹中的js文件中的公用文件夹中的映像?更具体地说,我正在设计一个div容器。我想将其backgroundImage属性设置为公用文件夹中的图像文件。我该怎么做呢?感谢您的回复!

    • 问题内容: 我正在尝试从文件中加载图像而不使用。这些文件夹是: 我想将图像加载到资产文件夹中。我试过了: 我已经尝试过使用字符串路径“ /TestProject/assets/drawIcon.png”,但是什么也没有。我不知道如何加载该图片! 问题答案: 将目录设置为资源目录,然后从“ /drawIcon.png”位置将图像加载为资源: 如果要创建javafx图像: 在这种情况下,也请将该文件夹

    • 有没有办法禁用文件夹的特定规则?例如,我不想在文件夹中为我的所有测试文件提供必需的JSDoc注释。有办法做到这一点吗?

    • 我目前正在使用此代码访问来自DCIM文件夹的最新图像- 然后获取图像 然后使用光标。moveToNext()以访问下一个图像。 但是,如果我必须以类似的方式访问另一个文件夹(如

    • 我正在寻找一种方法来获取zip文件中的文件列表。我创建了一个方法来获取目录中的文件列表,但我也在寻找一种方法来获取zip文件中的文件,而不是只显示zip文件。 以下是我的方法: