Java EE (v)

Source: Internet
Author: User
Tags sample html code

First, the Applet

An Applet is a Java program. It is typically run inside a Java-enabled Web browser. Because it has full Java API support, the applet is a full-featured Java application.

The important differences between standalone Java applications and applet programs are as follows:

  • The Applet class in Java inherits the Java.applet.Applet class.
  • The applet class does not define main (), so an applet program does not call the main () method.
  • Applets are designed to be embedded in an HTML page.
  • When the user browses to the HTML page containing the applet, the applet's code is downloaded to the user's machine.
  • A JVM is required to view an Applet. The JVM can be a plug-in for a Web browser, or a standalone runtime environment.
  • The JVM on the user's machine creates an instance of an applet class and invokes various methods in the applet life cycle process.
  • Applets have strict security rules enforced by WEB browsers, and the security mechanisms of applets are known as sandbox security.
  • Other classes required by the Applet can be downloaded in the form of a Java archive (JAR) file.
    The life cycle of an applet

    The four methods in the Applet class provide you with a framework that you can then develop applets on the framework:

    • Init: The purpose of this method is to provide any initialization required for your Applet. This method is called after the param tag inside the Applet tag is processed.
    • Start: The method is called automatically after the browser calls the Init method. This method is called whenever a user returns from another page to a page that contains an Applet.
    • Stop: This method is called automatically when the user removes from the page that contains the Applet. Therefore, you can call the method repeatedly in the same Applet.
    • Destroy:This method is called only when the browser shuts down gracefully. Because applets are only valid on HTML pages, you should not omit any resources after the user leaves the page containing the applet.
      • Paint:The method is called immediately after the start () method, or when the Applet needs to be redrawn in the browser. The paint () method actually inherits from the java.awt.
        Applet class

        Each applet is a subclass of the Java.applet.Applet class, and the underlying applet class provides a way to invoke the derived class to get the information and services of the browser context.

        These methods do the following things:

          • Get the parameters of the Applet
          • Get the network location of the HTML file that contains the Applet
          • Get the network location of the Applet class directory
          • Print Browser status information
          • Get a picture
          • Get an audio clip
          • Play an audio clip
          • Resize this Applet

        In addition, the applet class provides an interface for viewer or browser to obtain information about applets and to control the execution of applets.

        The Viewer may be:

          • Request information about the Applet author, version, and copyright
          • Description of the parameter that the request Applet recognizes
          • Initializing applets
          • Destroying applets
          • Start executing applets
          • End Execution Applet

        The Applet class provides a default implementation of these methods, which can be overridden when needed.

        "Hello,world" applets are written according to standards. The only method that is overridden is the paint method.

        The invocation of the Applet

        An Applet is a Java program. It is typically run inside a Java-enabled Web browser. Because it has full Java API support, the Applet is a full-featured Java application.

        <applet> tags are the basis for embedding applets in HTML files. The following is an example of invoking the "Hello World" applet;

        Sample HTML code:<html> <Title>The Hello, World Applet</title>
        <hr> <applet Span class= "Hl-var" >code= " Helloworldapplet.class " width = "320" height= " 120 "> < Span class= "hl-string" > < Span class= "Hl-var" > if your browser was java-enabled, a "Hello, World " < Span class= "hl-quotes" > < Span class= "Hl-code" > message would appear here. < Span class= "Hl-code" > < Span class= "hl-quotes" > </applet > < Span class= "hl-quotes" > < Span class= "hl-brackets" > <hr > < Span class= "hl-string" > < Span class= "Hl-var" > </html< Span class= "Hl-brackets" >>
    Second, Ajaxajax namely "ASynchronousJAvascript andXML"(Asynchronous JavaScript and XML) is a web development technique that creates an interactive Web application. Ajax = Asynchronous JavaScript and XML (a subset of standard generic markup languages). Ajax is a technique for creating fast, Dynamic Web pages. Ajax is a technique that can update parts of a Web page without reloading the entire page.[1]Ajax enables Web pages to be updated asynchronously by exchanging small amounts of data in the background with the server. This means that you can update a part of a webpage without reloading the entire page. Traditional Web pages (without Ajax) if you need to update the content, you must reload the entire page page.
    1. Working principle

    Ajax works by adding a middle-tier (Ajax engine) between the user and the server, making the user operation asynchronous with the server response. Not all user requests are submitted to the server, such as data validation and processing, to be done by the Ajax engine itself, only to determine the need to read new data from the server and then by the Ajax engine to submit the request to the server.

    2. Comparison with traditional Web applications

    The traditional Web application interaction triggered by the user an HTTP request to the server, the server processes it and then returns a new HTHL page to the client, each time the server processes the client-submitted request, the customer can only idle wait, and even if only a small interaction, Just get a very simple data from the server side, all to return a full HTML page, and the user each time to waste time and bandwidth to re-read the entire page. This practice wastes a lot of bandwidth, and the response time of the application depends on the response time of the server, because each application's interaction needs to send a request to the server. This causes the user interface to respond much more slowly than the local application. Unlike this, an AJAX application can send and retrieve only the necessary data to the server, using SOAP or some other XML-based Web service interface, and using JavaScript on the client to process the response from the server. Because the amount of data exchanged between the server and the browser is much reduced, the result is that we can see applications that respond faster. At the same time, a lot of processing can be done on the client machine making the request, so the processing time of the Web server is also reduced.

    3. Pros and cons

    (1). The advantages of Ajax
    <1>: No refresh update data.
    The biggest advantage of Ajax is the ability to communicate with the server to maintain data without refreshing the entire page. This enables the Web application to respond more quickly to user interactions and avoids sending information that is not changed on the network, reducing user latency and bringing a very good user experience.
    <2>. Asynchronously communicates with the server.
    Ajax uses asynchronous methods to communicate with the server, without interrupting the user's operations and having more rapid responsiveness. Optimize communication between browser and server, reduce unnecessary data transfer, time and reduce traffic on network.
    <3>: Front-end and back-end load balancing.
    Ajax can pass on some of the previous server workloads to the client, take advantage of the client's idle ability to handle, reduce server and bandwidth burden, save space and broadband rental costs. and reduce the burden of the server, the principle of Ajax is "on-demand data", can minimize the redundancy request and response to the burden on the server, improve site performance.
    <4> standards-based is widely supported.
    Ajax is based on standardized and widely supported technologies that do not require a browser plugin or applet to be downloaded, but require the client to allow JavaScript to be executed on the browser. With the maturation of Ajax, a number of libraries that simplify the use of Ajax have been introduced. Similarly, there is another assistive programming technique that provides alternative functionality for users who do not support JavaScript.
    <5>: interface and application separation.
    Ajax separates the interface in the Web from the application (or the separation of data and rendering), facilitates division of labor, reduces web application errors caused by non-technical changes to the page, improves efficiency, and is more applicable to today's publishing systems.

    (2). Disadvantages of Ajax
    <1>. Ajax kills back and the history function, which is the destruction of the browser mechanism.
    In the case of dynamically updating the page, the user cannot go back to the previous page state because the browser can only remember the static pages in the history. The difference between a fully read page and a page that has been dynamically modified is very subtle; The user will typically want to click the Back button to cancel their previous operation, but in an AJAX application this will not be possible.
    The Back button is an important feature of a standard web site, but it does not work well with JS. This is a serious problem with Ajax, because users often want to be able to undo the previous operation by going backwards. So is there any way to do this question? The answer is yes, using Gmail know, Gmail under the Ajax technology to solve the problem, in Gmail can be back, but it does not change the mechanism of Ajax, it is only a relatively stupid but effective way, that is, the user click the Back button to access the history To reproduce the changes on the page by creating or using a hidden iframe. (for example, when a user clicks back in Google Maps, it searches in a hidden iframe and then reflects the search results on an AJAX element to restore the application state to its current state.) )
    However, while this problem can be solved, the cost of development is very high and deviates from the rapid development required by the AJAX framework. This is a very serious problem caused by Ajax.
    A related view is that using dynamic page updates makes it difficult for users to save a particular state to a collection. The solution for this problem has also occurred, with most of the URL fragment identifiers (often referred to as anchors, which are the parts of the # URL) to keep track of, allowing the user to return to the specified application state. (many browsers allow JavaScript to dynamically update the anchor point, which allows an AJAX application to update the anchor point while updating the display.) These solutions also address many of the arguments that do not support back buttons.
    <2>. Security issues with Ajax.
    Ajax technology provides users with a good user experience, but also brings new security threats to it enterprises, Ajax technology is like the enterprise data set up a direct channel. This allows developers to inadvertently expose more data and server logic than ever before. The logic of Ajax can be hidden from the client's security scanning technology, allowing hackers to create new attacks from remote servers. And Ajax also makes it difficult to avoid some known security weaknesses, such as cross-site footstep attacks, SQL injection attacks, and credentials-based security vulnerabilities.
    <3> Support for search engines is weak.
    Support for search engines is weaker. If used improperly, Ajax can increase the flow of network data, thereby reducing the overall system performance.
    &LT;4&GT: The exception handling mechanism of the sabotage program.
    At least for now, these Ajax frameworks, like Ajax.dll,ajaxpro.dll, can disrupt the program's exception mechanism. On this issue, had encountered in the development process, but looked at the internet there is little relevant introduction. Later, an experiment was done to delete a piece of data using Ajax and the traditional form submission mode ... It has brought us a lot of difficulties in debugging.
    <5&gt: Violates the original intention of URL and resource location.
    For example, I give you a URL address, if you use Ajax technology, perhaps you see below the URL address and what I see under this URL is different. This is contrary to the original intention of resource positioning.
    <6>. Ajax does not support mobile devices very well.
    Some handheld devices (such as mobile phones, PDAs, etc.) are not yet well-supported Ajax, for example, when we open a website with Ajax technology on a mobile phone's browser, it is currently unsupported.
    <7> client-side fat, too many client-side code causes development costs.
    Write complex, error-prone, redundant code is more (layer contains JS file is the common problem of Ajax, coupled with many of the previous service-side code is now placed on the client), destroying the original standards of the Web.

Java EE (v)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.