After the ASP (ActiveServerPage) has been launched from Microsoft, it has been liked by its powerful function, simple and easy to learn. However, it has the common disease of Microsoft products, can only be used under the Windows platform, although it can be used under Linux by adding controls, but its most powerful DCOM control cannot be used. The JSP (Java Serverpages) developed at Java's basis achieved the separation of dynamic pages and static pages, separated from the binding of the hardware platform, and the compiled operation, etc., greatly improved its execution efficiency and gradually became an Internet. Mainstream development tool. In order to use the major to apply ASP programmers to learn JSP. It is now contrast, as follows:
First, structure
JSP and ASP are similar in structure, which is "" as a standard, which is different from the code ASP between the standards as JavaScript or VBScript scripts, while JSP is Java code. JSP is separated from the representation of the webpage and the code logic of the server side. As the JSP page of the server process, first converted to servlets (a Java program running on the server). Servlet supports requests and responses to HTTP protocols. When JSP is converted into a pure Java code. When multiple users are simultaneously requested a JSP page, apply an instantiation thread to respond to request. These threads are managed by the web server process, similar to the ASP's thread manager function. This way is more efficient than the mode comparison of CGI to create a process for each request.
Second, performance and platform irrelevant
Compared to language such as C , VB, Java is considered a language that is less efficient, but it is in exchange for the platform independence to make Java can run on most operating systems without need to recompile - Many people Willing to pay for this. Java's compile code is a byte code that 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 adopt "minimum bithom" 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 run in the server side, do not need to load heavy GUI (HTML GUI is very small). In addition, Servlets' byte code is only performed when the client request is requested, so although the loading time of a few seconds is a few seconds when calling servlets, the subsequent request is very rapid, because the server has cached the running servlets. The current JSP server has a Java Instant Compiler (JIT), so the execution of JSP is fast than the ASP code executed every time, especially when there is a loop operation in the code, JSP speed is fast 1 To 2 orders.
Third, session management
In order to track the user's operating state, the ASP application session object. JSP uses a object called HTTPSession to achieve the same function. The SESSION information is saved in the server side, and the session ID is saved in the cookie of the client. If the client prohibits cookies, the session ID must be taken behind the URL. Session typically sets a 30-minute expiration time on the server and automatically invalidate after the customer stops the activity. The information saved and retrieved in the session cannot be the basic data type (int, double), etc., but must be the corresponding Object (object) of Java (INTEGER, DOUBLE).
HttpSessionSession = Request.getSession (); // Get a session object or create one
Session.getID () // Get sessionID number integer = (Integer) // Retrieves the value of the session and transforms into integer session.putValue ("itemValue", itemname); // itemValue must Not a Must simple type
Fourth, Application Management
Sometimes servers need to manage parameters for the entire application so that each customer can get the same parameter value. Like Session, ASP uses Application objects and JSP uses servletContext objects, and the method of operation and session.
GetServletContext (). SetAttribute ("item", itemvalue); // Set an application variable
Integeri = (Integer) GetServletContext (). GetAttribute ("itemname"); // Get // Item
V. ServersideInCludes
ASP and JSP have the same place on server-side references. Both ASP and JSP can support this feature server (IIS, APACHE) to implement the server-side containing virtual files. But JSP is included in the result of the dynamic page instead of the code itself containing the file. When you contain the files on another server, it does not contain any code and objects is a very effective feature.
ASP:
JSP:
6. Java components: javabeans
JavaBeans is some object data that completes the packaging of predefined features. JavaBeans and JSP engagement are compared to COM and ASP, as follows:
COM objects are commonly used to encapsulate business logic and complete high intensity calculations for the ASP page. Reuse components make the page simple and fast because components are composed of compilation languages (C , VB) instead of interpretation Scripting language (VBScript, JScript).
Javabeans can only develop in Java language, COM can be developed by any language that meets the standard object model (including Visual J ). On the other hand, JavaBeans is easier to develop because once mastered 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 C and VB's foundation, additional efforts are needed. 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 do not need to re-register, if developers don't need to get full access to the server, this is a huge advantage.
You can create a complete JavaBeans library that meets business logic, allowing non-programmers to use library to develop dynamic sites.
Beans can manage database connections on the server side.
JavaBeans meets the structured object model: Each bean is controlled by a constructor without parameters, which controls its servlet to set its properties using the Introspection. To set the built-in properties of the bean, you must use the SetProperty tab with the property name. If a property can be set, the bean needs to have a setXXXX method, and XXXX is replaced with the actual properties.
Seven, JSP and database
ASP uses ODBC through the ADO connection database, while Java is connected to a JDBC technology linkage. The target database requires a JDBC driver - a database with Java interface that allows Java to access the database in a standard manner. 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 a JDBC driver, only the ODBC driver, Java provides a JDBC-ODBC bridge to convert JDBC calls to ODBC calls. All Java compilers have a free JDBC-ODBC bridge. In theory, the bridge can access any common database products. Conclusion: The JSP model is defined after the ASP, which 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 Windows-based technology, while Java and JSP are cross-platform.