阻止/显示“正在工作...”的最佳方式外部调用耗时的Java命令时的通知

发布于 2024-11-15 21:13:09 字数 691 浏览 0 评论 0原文

我有一个可以从 shell 调用的 Java 类。 (通过“java [command][options]”)该类接受一组参数并输出一个 MIDI 文件。

我想要做的是设置一个简单的 Web 应用程序,它从预先确定的目录中读取数据,该目录始终包含 3 个 MIDI 文件(仅!)。网络应用程序的访问者会看到这三个文件,并且必须选择他/她认为最好的一个(提交表格)。 Web 应用程序将使用该信息通过 Java 类生成一组 3 个新的 MIDI 文件,同时将信息记录到日志文件并将旧文件移动到存档目录。

我不确定的三件事是:

1)哪种网络语言最适合这个?我计划在某个时候将其制作成一个成熟的应用程序,但对 Java 的依赖使我认为使用 Servlet 是正确的选择。然而,PHP 或 Rails(例如)会更容易吗?是否可以/可能通过 PHP 或其他语言的 shell 命令调用 Java?

2)生成MIDI需要一些时间,所以我希望在用户提交表单后屏幕上出现某种加载栏或“等待...”通知。基本上,我希望应用程序在执行 shell 命令时阻止并显示该通知,并在命令完成并生成新的 MIDI 时呈现新页面。有没有我可以遵循的示例来实现此目的(带有 PHP 或 Servlet 的 AJAX 会很好)?

3)当超过一个人在网站上,并且一个人提交表单(并开始生成 MIDI)时,我希望每个人都能收到加载通知或至少触发一些操作。有没有一种干净的方法来做到这一点?

感谢任何回复!

I have a Java class which can be called from shell. (via "java [command][options]") The class takes in a set of parameters and outputs a MIDI file.

What I want to do is set up a simple webapp which reads from a pre-determined directory which will always contain 3 MIDI files (only!). A visitor to the webapp is presented with these three files, and has to choose one which s/he thinks is the best (submit a form). The webapp will use that information to generate a set of 3 new MIDI files using the Java class, while recording info to a log file and moving the old files to an archive directory.

The 3 things which I'm not sure about are:

1) What web language would be best for this? I plan to make this into a full-fledged app at some point, but the dependency on Java makes me think using Servlets is the way to go. However, would PHP or Rails (for ex.) be easier? Is it okay/possible to call Java via a shell command from PHP or other languages?

2) Generating the MIDI takes some time, so I want some sort of loading bar or "Waiting..." notice to appear on screen after the user submits the form. Basically I want the app to block and show that notice while the shell command executes, and render the new page when the command finishes and the new MIDIs are generated. Is there any example that I can follow to achieve this (AJAX with PHP or Servlets would be nice)?

3) When more than one person is on the website, and one person submits the form (and starts the MIDI generation), then I want everyone to get a loading notice or at least trigger some action. Is there a clean way to do this?

Thanks to any responses!

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

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

发布评论

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

评论(2

三生池水覆流年 2024-11-22 21:13:09

你的问题有点开放式,你以后应该尽量集中你的问题。不过我会尽力给你一些指导。

1) 我不一定说有一种“最佳”方法可以做到这一点,因为您可以轻松使用任意数量的解决方案。您有构建 Web 应用程序的经验吗?如果是这样,请使用您熟悉的内容。如果没有,也许可以选择您熟悉的语言的框架,或者尝试使用该语言从头开始创建服务器。

2)3) 涉及实现功能,同样,您可以通过多种方式来实现。 Ajax 绝对是解决这两个问题的一种方法。我认为您应该对您计划使用的技术进行更多研究,以便您更加了解它们的功能。尝试使用 Ajax 创建一个解决方案,看看它是如何工作的。

Your questions are a bit open ended, you should try to focus your questions a little more in the future. I'll try to give you some guidance though.

1) I wouldn't necessarily say there is a "best" way to do this, as you could easily use any number of solutions. Do you have any experience with building a web application? If so, use what you're familiar with. If not, maybe choose a framework in a language you're comfortable in, or explore creating a server from scratch in that language.

2) and 3) concern implementing features, again, you could do it in a number of ways. Ajax is definitely one way of approaching both these problems. I think you should do a little more research about the technologies you plan on using so you're more aware of their capabilities. Try creating a solution using Ajax and see how that works.

难以启齿的温柔 2024-11-22 21:13:09

如果可能的话,您应该向网络用户提供真实的反馈。使用 进度条,您可以使用 AJAX 调用 servlet 或任何检查的服务器端脚本程序的状态并获得完成百分比。

这里会有两种不同的操作。您提到的第一个是开始处理 MIDI。第二个操作是检查应用程序的状态。如果您(就像您所说的那样)一次只能运行一个进程,那么这一秒就更重要了。

您可以考虑的一个想法是在完成处理后通过电子邮件向用户发送最终文件的链接。如果每个用户需要很长时间,并且您有很多用户,则网页可能需要很长时间才能响应用户。这是一个糟糕的想法,大多数用户会发现这是不可接受的。电子邮件等替代交付方式可能更受欢迎。

You should provide the web user with real feedback if possible. Using a progress bar, you could use AJAX to call a servlet or any server side script that checks on the status of the program and get a percentage complete.

There would be two different operations here. The first that you mention would be to start processing the MIDI. The second operation would be to check the status of the application. This second is even more important if you (as it seems like you are saying) can only run one process at a time.

One idea you could consider is emailing the user a link to the final files after you are done processing. If it is going to take a long time for each user, and you have many users, it could that ages for a webpage to ever respond to the user. That's a terrible idea and most users will find that unacceptable. An alternative delivery method such as email, may be more palatable.

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