After Microsoft launched ASP (ActiveServerPage), it is loved by the majority of people with its powerful features and easy -to -learn. However, it has a common problem of Microsoft products and can only be used under the Windows platform. Although it can be used under Linux by increasing control, its most powerful DCOM control cannot be used. The JSP (Java Serverpages) developed by Sun Company under the basis of Java realizes the separation of dynamic pages and static pages, separated from the restraint of the hardware platform, and the post -compilation operation has greatly improved its execution efficiency and gradually become the Internet Internet. Mainstream development tools. In order to use the majority of programmers applying ASP, they can learn JSP quickly. The similarities and similarities are as follows: below:
1. Structure
JSP and ASP are similar in structure. Both use "<%" and "%>" as the marking symbols. The difference is that the code ASP between the marks is JavaScript or VBScript script, and JSP is Java code. JSP separates the expression form of the webpage with the code logic of the server side. As the JSP page of the server process, it was first converted into a Servlet (a server -side Java program).
Servlet supports the request and response of the HTTP protocol. When JSP is converted into a pure Java code. When multiple users request a JSP page at the same time, apply instantiated threads to respond to the request. These threads are managed by the Web server process, similar to the ASP thread manager function. Compared with CGI for each request to create a process, this method is much more efficient.
2. Performance and platform irrelevant
Compared with languages such as C ++, VB, Java is regarded as a less efficient language, but it is exchanged for the platform's irrelevant to sacrifice efficiency. Willing to pay for it for this. Java's compilation code is a byte code, which is explained by a Java VirtualMachine (JVM) virtual machine on the operating system.
Byte code can be migrated on all platforms without any changes. Cross -platform programming tends to adopt the "minimum centers" of all operating systems, especially when using a graphical interface (Servlets does not require any graphical interface).
Servlets is faster than traditional Java programs (Applets, JavaApp), because they are running on the server and do not need to load heavy GUI (very few GUIs of HTML). In addition, the byte code of the ServiceS is only executed when the customer's request is performed, so although there will be a few seconds of loading time when the service is called for the first time, the subsequent request is very fast, because the server has cached the running Servlets.
The current JSP server has a Java instant compiler (JIT). Therefore, the execution of JSP is faster than each time explaining the execution of the execution, especially when there is a cycle operation in the code, the speed of the JSP is faster 1 1 1 1 1 1 1 1 1 1 is fast 1 1 1 1 1 1 1 1 is faster 1 1 1 1 1 1 1 is faster 1 1 1. To 2 quantities.
3. SESSION management
In order to track the user's operation status, the ASP application session object. JSP uses an object called httpsession to achieve the same function. The information of session is saved on the server, and the id of Session is saved in the Cookie of the client. If the client prohibits Cookie, the session ID must be brought behind URL.
Session generally set a 30 -minute expiration time on the server, and automatically fails after the customer stops the activity. The information saved and retrieved in session cannot be the basic data types, such as int, double, etc., but must be the corresponding Object (object) of Java.
4. Application management
Sometimes the server needs to manage parameters facing the entire application so that each customer can get the same parameter value. Like session, ASP uses the Application object and JSP uses the ServiceContext object, the operation method is the same as the session.
5. Serversideincludes
ASP and JSP are the same on the server. ASP and JSP can support the server (IIS, Apache) that support this feature to implement virtual files. But JSP is included in the results of the dynamic page, not the code itself containing the file itself. When the files you contain are on another server, it is a very effective feature without any code and object.
6. Java component: javabeans
JavaBeans is an object data for some packaging that completes predetermined functions. JavaBeans and JSP are compared to COM and ASP as follows:
COM objects are often used to encapsulate business logic and complete high -intensity calculations for ASP pages. The reusable component makes the page simple and fast, because the component consists of compile language (C ++, VB), not the interpreted Scripting language (VBScript, JScript).
JavaBeans can only be developed in Java language, and COM can be developed by any language (including Visual J ++) that meets the standard object model. On the other hand, JavaBeans is easier to develop, because once you master Java, it is very easy to understand the structure of JavaBeans. Due to the complexity of COM, you need a lot of learning and training to master-even if you have the foundation of C ++ and VB, you need additional efforts.
The COM component needs to be registered on the server. If you modify an existing component, the server needs to be restarted to use it. JavaBeans does not need to register. If developers do not need to get complete access to the server, this is a huge advantage. Can create a complete JavaBeans library that meets business logic, allowing non -programming personnel to use libraries to develop dynamic websites.
Beans can manage database connections on the server side.
JavaBeans conforms to a structural object model: Each bean is set up by a constructor with a constructor without parameter parameters. To set the built -in attributes of Bean, you must use the Setproperty tag with a attribute name. If a attribute can be set, Bean needs a setxxxx method, and XXXX replaces it with the actual attribute name.
7. JSP and database
ASP uses ODBC to connect to the database through ADO, and Java connects the database called JDBC technology. The target database requires a JDBC driver-an excuse for a database and Java, so that Java can access the database in a standard way. JDBC does not use the data source of the server. As long as there is a JDBC driver, Java can access the database. If a specific database does not have the JDBC driver, but only the ODBC driver, Java provides a JDBC-ODBC bridge to transform JDBC calls into ODBC calls. All Java compilers have a free JDBC-ODBC bridge. Theoretically, bridges can access any common database products.
in conclusion:
The JSP model is defined after ASP. It borrows many advantages of ASP, such as Session, Application and other objects. At the same time, JSP uses flexible and powerful Java language, not inefficient Scripting language. ASP developers can only use technology based on Windows platform, while Java and JSP are cross -platform.