苹果程序和Servlets的区别

苹果程序和Servlets的区别

前提是: Servlets和Applets

苹果电脑 小程序
Java小程序是一个用Java编写的小程序,以字节码的形式提供给用户。 Servlet是一个Java编程语言类,用于扩展服务器的功能。
小程序是在客户端执行的。 Servlet则在服务器端执行。
Applets被用来为网络应用程序提供交互式功能,这些功能不能由HTML单独提供,如捕获鼠标输入等。 Servlets是其他动态Web内容技术(如PHP和ASP.NET)的Java对应物。
小程序的生命周期有:init(), stop(), paint(), start(), destroy()。 servlets的生命周期是:init(), service(), and destroy()。
Applets中可用的包是:- import java.applet.*; and import java.awt.*. 在servlets中可用的包有:– import javax.servlet.*; and import java.servlet.http.*;
Applets使用用户界面类,如AWT和Swing。 不需要用户接口。
Applets更容易产生风险,因为它在客户端机器上。 Servlet是在服务器的安全之下。
由于Applets在客户端机器上执行,所以它占用了更多的网络带宽。 Servlets在服务器上执行,因此需要较少的带宽。
需要兼容java的浏览器来执行。 它接受来自浏览器的输入,并以HTML页面、Javascript对象、Applets等形式生成响应。
Applets有两种类型 1.) 不受信任的Applets 2.) 受信任的Applets Servlet有两种类型 1.) 通用Servlet 2.)HTTP Servlet
Applets是JSE(JAVA Stander Edition)模块的一部分。 Servlet是JEE(Java企业版)模块的一部分。

举例说明

  • 创建 “hello world “Applet。
// A Hello World Applet
// Save file as HelloWorld.java
 
import java.applet.Applet;
import java.awt.Graphics;
 
// HelloWorld class extends Applet
public class HelloWorld extends Applet {
 
    // Overriding paint() method
    @Override
    public void paint(Graphics g)
    {
        g.drawString("Hello World", 20, 20);
    }
}
  • 创建 “hello world “Servlet。
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
 
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
 
    private String message;
 
    public void init() throws ServletException
    {
        // Do required initialization
        message = "Hello World";
    }
 
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws ServletException, IOException
    {
 
        // Set response content type
        response.setContentType("text/html");
 
        // Actual logic goes here.
        PrintWriter out = response.getWriter();
        out.println("<h1>" + message + "</h1>");
    }
 
    public void destroy()
    {
        // do nothing.
    }
}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程