Comparison between ASP and JSP (1)

Source: Internet
Author: User

Comparison between ASP and JSP
After Microsoft launched ASP (ActiveServerPage), it was liked by many WEB developers with its powerful functions and easy to learn features. However, it has common problems with Microsoft products and can only be used on Windows platforms. Although it can be used in LINUX by adding controls, its most powerful DCOM control cannot be used. The JSP (JAVA ServerPages) developed by SUN on the basis of Java achieves the separation of dynamic and static pages, which is out of the constraint of the hardware platform, the compilation and post-running methods greatly improve the execution efficiency and gradually become the mainstream development tools on the Internet. To use ASP, programmers can quickly learn JSP. The similarities and differences are as follows:

I. Structure

JSP and ASP are similar in structure. They both use "" as the identifier. The difference is that ASP code between the identifier is JavaScript or VBScript script, while JSP code is JAVA code. JSP separates the form of web pages from the code logic on the server. The JSP page of a server process is first converted into a servlet (a java program running on the server ). Servlet supports HTTP requests and responses. When JSP is converted into pure JAVA code. When multiple users simultaneously request a jsp page, the app instantiation thread responds to the request. These threads are managed by WEB server processes, which are similar to ASP thread manager functions. Compared with the mode in which CGI creates a process for each request, this method is much more efficient.

2. Performance and platform independence

Compared with C ++, VB, and other languages, JAVA is regarded as a language with low efficiency, but it sacrifices efficiency in exchange for platform independence so that JAVA can run on most operating systems without re-compilation-many are willing to pay for it. JAVA compilation code is a byte code, which is interpreted by a Java VirtualMachine (JVM) virtual machine on the operating system at runtime. Byte Code can be migrated on all platforms without any changes. Cross-platform programming tends to use the "minimum public Denominator" of all operating systems, especially when using graphical interfaces (servlets does not need any graphical interfaces ). Servlets is faster than traditional java programs (applets, javaapp) because they run on the server and do not need to load heavy guis (there are very few HTML guis ). In addition, the byte code of servlets is only executed when the customer requests it. Therefore, although it takes several seconds to load the first call to servlets, the subsequent requests are very fast, because the server has cached the running servlets. The current jsp server carries the java real-time Compiler (JIT). Therefore, JSP execution is faster than the ASP code that needs to be interpreted and executed every time, especially when cyclic operations exist in the Code, the JSP speed is 1 to 2 orders of magnitude faster.

Iii. Session management

ASP applies the SESSION object to track the user's operation status. JSP uses an object called HttpSession to implement the same function. The Session information is stored on the server, and the Session id is stored in the cookie of the client. If the client disables cookie, the Session Id must be followed by the url. Generally, a 30-minute expiration time is set for a Session on the server. The Session will automatically expire when the customer stops the activity. The stored and retrieved information in the Session cannot be the basic data type (primitivedatatypes) such as (int, double), but must be the corresponding java object (object) such as (Integer, Double ).

HttpSessionsession = request. getSession (); // get a session object or create

Session. getId () // obtain the number of sessionids

Integerid = (Integer) session. getValue ("id") // retrieves the session value and converts it to an integer session. putValue ("ItemValue", itemName); // The ItemValue must not be of the must simple type.

Iv. Application Management

Sometimes the server needs to manage parameters for the entire application so that each customer can obtain the same parameter value. Like Session, ASP uses the Application object while JSP uses the ServletContext object. The operation method is the same as Session.

GetServletContext (). setAttribute ("Item", ItemValue); // you can specify 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.