ASP and JSP comparison (i)

Source: Internet
Author: User
Tags object comparison integer session id thread client
Comparison of js| |js ASP with JSP (I.)

Since the introduction of the ASP (Activeserverpage), it is a powerful feature, simple and easy to learn the characteristics of the vast number of web developers like. But it has a common problem with Microsoft products that can only be used under Windows platforms, although it can be used under Linux by adding controls, but the most powerful DCOM control is not available. and Sun Company in Java based on the JSP (Java serverpages) to achieve a dynamic page and static page separation, out of the shackles of the hardware platform, as well as the compilation and operation of the way to greatly improve its implementation efficiency and gradually become the mainstream development tool on the Internet. In order to use the vast number of applications of the ASP program can quickly learn JSP. The similarities and differences are compared as follows:

First, the structure
The JSP and ASP are structurally similar, with "<%" and "%>" as the mark, unlike the code ASP for JavaScript or VBScript scripts, and the JSP is Java code. JSP separates the presentation of the Web page from the logic of the server-side code. As a JSP page for the server process, it is first converted to a servlet (a Java program running on the server side). The servlet supports the HTTP protocol's request and response. When the JSP is converted to pure Java code. When multiple users request a JSP page at the same time, the instance thread is applied to respond to the request. These threads are managed by the Web server process and are similar to the ASP's thread manager functionality. This is much more efficient than a pattern comparison of creating a process for each request with CGI.

Performance and platform-independent nature
Compared with C + +, VB and other languages, Java is seen as a less efficient language, but it is sacrificing efficiency in exchange for platform independence so that Java can run on most operating systems without recompiling-many people willing to pay the price. Java's compiled code is a byte code that is interpreted at run time by a Java virtualmachine (JVM) virtual machine on the operating system. The byte code can be migrated on all platforms without any changes required. Cross-platform programming tends to adopt the "lowest common denominator" of all operating systems, especially when using graphical interfaces (Servlets does not require any graphical interface). Servlets is faster than traditional Java programs (applets, Javaapp) because they run on the server side and do not need to load a heavy GUI (HTML GUI is very small). In addition, the Servlets byte code executes only when the client requests it, so although there will be a few seconds to load time when the Servlets is first invoked, subsequent requests are very fast because the server has cached the running servlets. The current JSP server, all with the Java Just-in-time compiler (JIT), so that the implementation of the JSP than every time to explain the execution of the ASP code faster, especially in the code when there is a loop operation, JSP speed of 1 to 2 orders of magnitude.

Third, session management
In order to track the user's operation status, ASP applies the Session object. JSP uses an object called HttpSession to achieve the same function. The session information is saved on the server side, and the session ID is stored in the client's cookie. If the client prohibits the Cookie,session ID, it must be brought behind the URL. Session typically sets a 30-minute expiration time on the server, which automatically expires when the customer stops the activity. The information saved and retrieved in the session cannot be the base data type (Primitivedatatypes) such as (int, double), and must be the corresponding object (object) of Java (integer,double).
Httpsessionsession=request.getsession ()//Get a Session object or create a
Session.getid ()//Get SessionID number
Integerid= (integer) session.getvalue ("id")//retrieves the value of the session and converts it to an integral type Session.putvalue ("Itemvalue", itemname); Itemvalue must not be must simple type

Iv. Management of Application
Sometimes the server needs to manage parameters for the entire application so that each customer gets the same parameter value. As with the session, ASP uses the Application object and the JSP uses the ServletContext object, the same way as the session.
Getservletcontext (). setattribute ("Item", itemvalue);//set an application variable
Integeri= (Integer) Getservletcontext (). getattribute ("ItemName");/Get//item



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.