Js| compared to the introduction of ASP from Microsoft (Activeserverpage), it has its powerful features, 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 a 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
Five, Serversideincludes
ASP and JSP have the same place on the server side references. ASP and JSP can support this functionality on the server (Iis,apache) to implement server-side contains virtual files. But the JSP is to include the result of the dynamic page, not the code itself that contains the file. When you include files on another server, it is a very effective function to not include any code and objects.
asp:<!--#includefile = "subfile.asp"--> jsp:<% @includefile = "subfile. JSP "-->
VI. Java components: JavaBeans
JavaBeans is the encapsulated object data that completes the predefined functions. The JavaBeans and JSP engagement are compared to COM and asp:
COM objects are commonly used to encapsulate business logic and to perform high-intensity computations for ASP pages. Reusable components make the page simple and fast, because the component is composed of a compiled language (C++,VB) rather than an interpreted scripting language (VBScript, JScript).
JavaBeans can only be developed in the Java language, and COM may be developed by any language that conforms to the standard object model (including Visual J + +). On the other hand, JavaBeans is easier to develop, because once you've mastered Java, it's easy to understand the structure of JavaBeans. Because of the complexity of COM, you need a lot of learning and training to master-even if you have C + + and VB Foundation also need extra effort.
Com components need to be registered on the server, and if you modify an existing component, the server needs to be restarted to use it. JavaBeans does not require a re-register, which is a great advantage if the developer does not need full access to the server. You can create a complete JavaBeans library that satisfies business logic, allowing non-programmers to use libraries to develop dynamic Web sites.
Beans can manage database connections on the server side.
JavaBeans conforms to the Structured object model: Each bean consists of a constructor with no parameters, and the servlet that controls it can set its properties using introspection (introspection). To set the bean's built-in properties, you must use the SetProperty label with the property name. If a property can be set, the bean needs to have a setxxxx method, and XXXX replaces it with the actual property name.
Seven, JSP and database
ASP uses ODBC to connect to the database through ADO, while Java joins the database through a technology called JDBC. The target database requires a JDBC driver--a database and Java excuse that allows Java to access the database in a standard way. JDBC does not use server-side data sources. As long as there is a JDBC driver, Java can access the database. If a particular database does not have a JDBC driver, and only the ODBC driver, Java provides a JDBC-ODBC bridge to convert the JDBC call into an ODBC invocation. All of the Java compilers are equipped with a free JDBC-ODBC bridge. In theory, a bridge can access any common database product.
Conclusion:
The JSP model is defined after the ASP, and it borrows many of the benefits of ASP, such as Session,application and other objects. JSP also uses a flexible and powerful Java language, rather than an inefficient scripting language. ASP developers can only use windows-based technology, while Java and JSP are cross-platform.