从 servlet 启动 applet
我一直在寻找如何从 servlet 启动小程序。到目前为止,Web 上的所有内容都是相反的,从 applet 连接到 servlet。我正在编写一个 gwt/j2ee 应用程序,需要将数据发布到 servlet,然后让 servlet 启动一个小程序并将序列化对象传递给该小程序。然后,小程序会将数据发送回 servlet。有什么想法吗?提前致谢。
I have been searching on how to start an applet from a servlet. Everything on the web so far has been on the opposite, connecting to a servlet from an applet. I am writing a gwt/j2ee app and need to post data to a servlet, then have the servlet start an applet and pass serialized objects to the applet. The applet would then send data back the the servlet. Any ideas? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不会也不可能用 Servlet 启动 applet。您只需让小程序在其
init()
为 applet 需要的任何数据调用 servlet,并让 servlet 返回所需的数据。 Applet-Servlet 通信可以借助 Applet 中的 HTTP 客户端来完成。基本的 Java SE API 为您提供java.lang. net.URL
和java.net.URLConnection
为此。此处,
servletURL
应与您在web.xml
中定义的 servlet 的url-pattern
相匹配,例如/servletURL 或 <代码>/servletURL/*。
另请参阅:
URLConnection
触发和处理 HTTP 请求You don't and can't start an applet with a Servlet. You just let the applet during its
init()
call the servlet for any data the applet needs and have the servlet return the desired data. Applet-Servlet communication can be done with help of a HTTP client in the applet. The basic Java SE API offers youjava.net.URL
andjava.net.URLConnection
for this.Here,
servletURL
should match theurl-pattern
of the servlet as you definied in theweb.xml
, e.g./servletURL
or/servletURL/*
.See also:
URLConnection
小程序是通过浏览器读取指定小程序的 HTML、下载小程序的代码并运行它来启动的。
您的 servlet 只需要以正常方式提供描述 applet 的 HTML,然后也提供代码,或者从静态站点下载该代码(如果您明白我的意思)。基本上只需记住 servlet 的作用是向客户端提供数据。考虑客户端需要哪些数据才能启动小程序 - 并提供该数据。
An applet is started by the browser reading the HTML specifying the applet, downloading the applet's code, and running it.
Your servlet just needs to serve up HTML describing the applet, in the normal way - and then either serve the code as well, or let that be downloaded from a static site (if you see what I mean). Basically just remember that the servlet is there to serve data to the client. Think about what data the client needs in order to start the applet - and serve that data.