向 Vaadin 7 应用程序添加第二个 UI 会导致问题

发布于 2025-01-09 01:50:44 字数 3529 浏览 0 评论 0原文

我有一个 Vaadin 7 应用程序,最初只有一个 UI。发生了以下事情,我不介意甚至喜欢:

  1. 当安装新的 WAR 文件时,当前打开该 URL 的所有浏览器选项卡都会出现黑色的“连接失败”或“会话过期”错误,迫使我刷新。此外,在部署应用程序时,我经常会在右上角收到“服务器加载”错误。这有点难以解释,但希望这是有道理的。这些都不是由我的代码直接触发的,所有这些都是我从 Vaadin 开箱即用的行为。
  2. 如果我在多个浏览器选项卡中登录到同一网站(和同一用户),然后退出一个选项卡,则我用于注销/停用所有选项卡的代码效果很好 - 正如我编码的那样,它们都返回到登录屏幕他们到。

当时,我的 web.xml 如下:

web-app id="WebApp_ID" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>vaadinwebsite</display-name>

    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>${productionMode}</param-value>
    </context-param>
    <servlet>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <servlet-class>com.mobiwms.website.WmsServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.mobiwms.website.WmsUI</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
<!-- Uncomment if add more than one UI 
    <servlet-mapping>
        <servlet-name>Vaadintutorial</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>
 -->
... <!-- some other stuff-->
</web-app>

我最近添加了第二个 UI,这意味着我需要调整第一个 UI 的路径。所以我做了以下操作:

  1. 更改了 web.xml,使其使用 3.0,并注释掉 web.xml 中的 servlet 引用,以便它将在代码中使用 WebServlet 注释。
  2. 将我的第一个 UI 的 url 模式从 @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true) 更改为 @WebServlet(urlPatterns = {"/*" , "/VAADIN/*"}, name = "WmsServlet", asyncSupported = true),根据文档。因此,这使得“根”应用程序成为我的主 UI,就像我只有一个 UI 时一样。根据上面的 web.xml 片段,我的 url 模式始终为“/*”。
  3. 使用 @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = true) 添加了新的 UI 和 URL 模式。

现在我遇到了以下奇怪的情况:

  1. 安装新的 WAR 不会强制我刷新。换句话说,我什至没有注意到我需要刷新,直到我开始做某事,此时我得到正常的黑色“通信失败”,就像正常情况一样。
  2. 当我在两个选项卡上登录并注销时,它肯定会使另一个选项卡中的会话无效(我看到黑色的“通信失败”错误),但它不会像以前那样返回到登录屏幕。
  3. 我们多次看到无法加载小部件集错误。
  4. 有时,当我们在做事情时,例如上传文件,我们会收到黑色的“通信失败”错误。

这两个 UI 和 servlet 非常相似,只是布局不同。较新的 UI 是注册 UI,因此实际上只有一种表单、一种视图,而且非常简单。另一个是成熟的应用程序。

我在较新的应用程序(注册 UI)上尝试使用 asyncSupported = false 进行操作,但这不起作用。然后我注释掉了 @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = false),因此实际上我的新 UI 无法访问。这也没有解决它。

由于我还更改了 web.xml,以便使用 3.0(web.xml 在此之前有 2.5),因此我将两个 UI servlet 的 asyncSupport 更改为 false,以便它与 2.5 的默认行为匹配。这也没有解决它。

于是我再次注释掉了 Registration WebServlet 注释,并将 @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) 更改为 < code>@WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = false) (因此摆脱了 VAADIN 引用)。这实际上解决了问题,现在一切都像以前一样。那么我处理 2 个 UI 的方式是错误的吗?也许我处理“/VAADIN/*”错误?

I have a Vaadin 7 application where I originally had just one UI. The following things happened, which I did not mind and even liked:

  1. When installed new WAR file, all browser tabs currently opened to that URL gave the black "Connection failed" or "Session expired" error, forcing me to refresh. Also, I would often get a "server loading" error in the upper right corner while the application deployed. This one is kind of hard to explain, but hopefully this makes sense. None of this was triggered by my code directly, all of it was behavior I got from Vaadin out of the box.
  2. If I was logged in to the same website (and same user) in multiple browser tabs, and then logged out of one tab, my code to logout/inactivate all tabs worked great - they all went back to the login screen, as I coded them to.

At that time, I had web.xml as follows:

web-app id="WebApp_ID" version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>vaadinwebsite</display-name>

    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>${productionMode}</param-value>
    </context-param>
    <servlet>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <servlet-class>com.mobiwms.website.WmsServlet</servlet-class>
        <init-param>
            <param-name>UI</param-name>
            <param-value>com.mobiwms.website.WmsUI</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <!-- <servlet-name>WmsUIServlet</servlet-name> -->
        <servlet-name>WmsServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    
<!-- Uncomment if add more than one UI 
    <servlet-mapping>
        <servlet-name>Vaadintutorial</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>
 -->
... <!-- some other stuff-->
</web-app>

I recently added a second UI, which meant I needed to tweak the path of the first UI. So I did the following:

  1. Changed web.xml so it uses 3.0, and comment out servlet references in web.xml so it would use WebServlet annotations in the code.
  2. Changed the url pattern of my first UI from @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true) to @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = true), as per the documentation. So this makes it so the "root" application is my main UI, like it was when I only had one UI. As per my web.xml snippet above, I always had a url pattern of "/*".
  3. Added a new UI and url pattern using @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = true).

Now I am getting the following weirdness:

  1. Installing a new WAR does not force me to refresh. In other words, I don't even notice I need to refresh until I start doing something, at which point I get the normal black "communication failed", like normal.
  2. When I am logged in on two tabs and logout, it definitely invalidates the session in the other tab (I see the black "communication failed" error), but it does not go back to the login screen like it used to.
  3. At various times we see a failed to load widgetset error.
  4. On occasion, when we are doing things, like uploading files, we get the black "communication failed" error.

The 2 UIs and servlets are much the same, just a different layout. The newer UI is a registration UI and so really only has one form, one view, and is very simple. The other is a full fledged application.

I tried it with asyncSupported = false on my newer application (the Registration UI), but that did not work. I then commented out @WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = false), so effectively my new UI is not accessible. This did not fix it either.

Since I also changed the web.xml such that I am using 3.0 (web.xml had 2.5 before this), I changed asyncSupport to false for both my UI servlets so it matches the default behavior for 2.5. This also did not fix it.

So then I commented out the Registration WebServlet annotation again and changed @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) to @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = false) (so got rid of VAADIN reference). This actually fixed things, and now things work like before. So am I handling 2 UI's wrong? Maybe I am dealing with "/VAADIN/*" wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2025-01-16 01:50:44

好吧,在多次阅读 文档 后,我终于注意到了一个小问题他们提出的观点是:

如果您提供服务,则无需提供上述 /VAADIN/* 映射
小部件集和(自定义和默认)主题都静态地位于
Web 应用程序中的 /VAADIN 目录。该映射简单地允许
从 Vaadin JAR 动态地为它们提供服务。静态地为他们提供服务
建议用于生产环境,因为它更快。如果你
从同一个 Web 应用程序中提供内容,您不能
具有 Vaadin servlet 的根模式 /*,因为所有
请求将被映射到 servlet。

因此,一旦我将 @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) 更改为 @WebServlet(urlPatterns = " /*", name = "WmsServlet", asyncSupported = true),事情好多了。由于我没有使用 VAADIN jar 文件,但 Vaadin 的内容在我的 WAR 文件中,该文件被分解到一个目录(据我所知,默认设置),它实际上是静态的,因此这是有效的。

顺便说一句,我设置了 asyncSupported = true 来解决“当前链的过滤器或 servlet 不支持异步操作”的问题。错误(我在此处提到了这个错误),尽管说实话,我并不是 100% 确定我必须这么做。因为它似乎不会伤害我,所以我将其保留为“true”。

Ok, after reading the documentation multiple times, I finally noticed one minor point they made:

You do not have to provide the above /VAADIN/* mapping if you serve
both the widget sets and (custom and default) themes statically in the
/VAADIN directory in the web application. The mapping simply allows
serving them dynamically from the Vaadin JAR. Serving them statically
is recommended for production environments as it is faster. If you
serve the content from within the same web application, you may not
have the root pattern /* for the Vaadin servlet, as then all the
requests would be mapped to the servlet.

So once I changed @WebServlet(urlPatterns = {"/*", "/VAADIN/*"}, name = "WmsServlet", asyncSupported = false) to @WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true), things worked much better. Since I am not using the VAADIN jar file, but the Vaadin stuff is in my WAR file that gets exploded to a directory (the default setup, as far as I know), it is effectively static, thus this works.

BTW, I set asyncSupported = true to get around the "A filter or servlet of the current chain does not support asynchronous operations." error (I mention this error here), although, honestly, I am not 100% sure I had to. Since it seems not to be hurting me, I left it as "true".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文