向 Vaadin 7 应用程序添加第二个 UI 会导致问题
我有一个 Vaadin 7 应用程序,最初只有一个 UI。发生了以下事情,我不介意甚至喜欢:
- 当安装新的 WAR 文件时,当前打开该 URL 的所有浏览器选项卡都会出现黑色的“连接失败”或“会话过期”错误,迫使我刷新。此外,在部署应用程序时,我经常会在右上角收到“服务器加载”错误。这有点难以解释,但希望这是有道理的。这些都不是由我的代码直接触发的,所有这些都是我从 Vaadin 开箱即用的行为。
- 如果我在多个浏览器选项卡中登录到同一网站(和同一用户),然后退出一个选项卡,则我用于注销/停用所有选项卡的代码效果很好 - 正如我编码的那样,它们都返回到登录屏幕他们到。
当时,我的 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 的路径。所以我做了以下操作:
- 更改了 web.xml,使其使用 3.0,并注释掉 web.xml 中的 servlet 引用,以便它将在代码中使用 WebServlet 注释。
- 将我的第一个 UI 的 url 模式从
@WebServlet(urlPatterns = "/*", name = "WmsServlet", asyncSupported = true)
更改为@WebServlet(urlPatterns = {"/*" , "/VAADIN/*"}, name = "WmsServlet", asyncSupported = true)
,根据文档。因此,这使得“根”应用程序成为我的主 UI,就像我只有一个 UI 时一样。根据上面的 web.xml 片段,我的 url 模式始终为“/*”。 - 使用
@WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = true)
添加了新的 UI 和 URL 模式。
现在我遇到了以下奇怪的情况:
- 安装新的 WAR 不会强制我刷新。换句话说,我什至没有注意到我需要刷新,直到我开始做某事,此时我得到正常的黑色“通信失败”,就像正常情况一样。
- 当我在两个选项卡上登录并注销时,它肯定会使另一个选项卡中的会话无效(我看到黑色的“通信失败”错误),但它不会像以前那样返回到登录屏幕。
- 我们多次看到无法加载小部件集错误。
- 有时,当我们在做事情时,例如上传文件,我们会收到黑色的“通信失败”错误。
这两个 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:
- 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.
- 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:
- 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.
- 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 "/*". - Added a new UI and url pattern using
@WebServlet(urlPatterns = "/Registration/*", name = "WmsRegistrationServlet", asyncSupported = true)
.
Now I am getting the following weirdness:
- 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.
- 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.
- At various times we see a failed to load widgetset error.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,在多次阅读 文档 后,我终于注意到了一个小问题他们提出的观点是:
因此,一旦我将
@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:
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".