Servlets 入门
接下来显示的 HelloWorldServlets 是一个显示字符串“ Hello World”的 Java 类。
A browser with JavaScript enabled is required for this page to operate properly\.
Note:
如果看不到示例正在运行,则可能需要在浏览器中启用 JavaScript 解释器,以便 Deployment Toolkit 脚本能够正常运行。
以下是 HelloWorldServlets 的源代码:
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class HelloWorld extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
诸如此类的 applet 通常由浏览器中的* Java Plug-in *软件 管理 和运行。
下载源代码用于“ Hello World”示例,以进行进一步试验。