JSP Advanced Programming 1

zhaozj2021-02-08  204

Chapter 1 Overview 1.1 Java Technology J a V A is a development tool that is simple and easy to use, fully faced objects, and is a platform-independent and safe and reliable. Since the official advent of 1 9 95, the rapid development of J A V A has made the entire We B world overweight change. With the launch of Java Servlet, J A V A began emerged in an e-commerce, and the latest Java Server Page technology is launched, and JA V A is a preferred development tool for WE B-based applications. To learn Java Server Page in J AVA technology is essential, this book will make a simple explanation of J ava based readers in Chapter 2, and Java Beans, etc., they are learning JSP must master J AVA knowledge. Here, look at the development history of J a V A and then explain the important concepts that will be used later. 1.1.1 Development of Java Technology J ava technology is advocated and introduced by the United States S UNI, J ava technology includes J ava language and Java Media Apis, Security Apis, Management Apis, Java Applet, Java RMI, J Ava B EANS, J Ava OS, Java Servlet, JDBC, JNDI, Enterprise JavaBeans, etc. are the development of J AVA technology. 1 990, S U N company James Gosling leadership team designed a platform independent language O A K, mainly used to write procedures for various household appliances. 1 9 9, January, OAK was renamed J a V a, 1 9 9, May 2 3, S U N officially issued J a V A and H O T J a V A browser on Sun World '9 5. 1 9 9 9 from August to February, N E T S C A P e Company, O R A C LE Company, B O R L A ND Company, S G i Company, A D O B E Company, I B M, AT & T Company, I N TET EL L company Get J a v A license. In January 9, January, S U N announced the establishment of a new business department ─ J A V A S O F T, developed, sold and supported J $ VA technology-based products, approved by Alan Baratz. At the same time, the J A VA Development Kit 1.0 is launched, providing developers to provide tools needed to prepare J a V A application software. 1 9 September 9, S U n Releases the J a V a chip series, including P i C O J a V A, M i C R O J a V A and U L T R A J A V A, and launches J A V A database connection JDBC (Java Database Connectivity). In March 9, March, S U N introduced Java WO R K S H o P. 1 9 96, M a C R O S O F T, S C O, Apple Computer Company (A P L E), N E C Company, etc. obtained J a v A license. Company S U N announced Apple Computer, H P, Hitachi, I B M, Microsoft, N O V E L, S G i, S C O, TA M D E M and other companies will embed J A V A platform into its operating system. Part 1 JSP Getting Started 1 9 9 JUST, H P Company, S Y B A S E Company got J a V license. Northern Telecommunications Company announced the application of J a V A technology and J a V A microprocessor to its next-generation phone.

On May 2 9th, S U N held the first J a V A O N e World J A VA Developer Conference in San Francisco, and the industry participated. S u n has launched a series of J a V a platform new technologies at the conference. In August 9, 9 June, Java Wo R K S H O P became the first product provided by S u n through the Internet. 1 9 September 9, A D D I S O N - WE S L E Y and S U N Introduces the J A V A Virtual Machine Specification and the J A V A Category Library. 1 9 9, 1 September, Texas Instruments, etc. Company obtained J a v A license. S u n Complete J a V A B E A n s specification and released. Release the first Java Jit (Just-In-Ti M e) compiler and intend to add J i T in Java WO R K S HO P and S O L A R I S operating system. 1 Past 9, S UN Releases J ava Enterprise Computing Technology, including J Ava S TATION network computers, 6 5 J ava products and applications released by J ava products, 7 new J ava training courses and J ava Consulting services, J ava-based S Olstice Internet mail software, new J ava developer support service, Demo HotJava Vi EWS, Java Tu Tor, complete Java Card API, etc. S u n announced the completion of the J a V Acard API specification, which is the first open A P i for smart cards. The Java Card specification will give J a V A capabilities to hundreds of millions of smart cards worldwide. 1 9 November 9, I B M gains J a V A O S and H O T J a V licenses. N o V E L1 gets Java WO R K S H O P license. S U N and I B M announced that both parties provide a wide-propaganda to provide J a V A, I B M agreed to establish the first J A V A inspection center. 1 9 9 Ji February, X E R O X and other companies get J a V A or J a V A O S license. S u n Releases JDK 1.1, J A V A Business Toolkit, J A V A B E A N S Development Kit and a Series Java APIS. A new Java Server product line is launched, including Java WE BS E R V E R, Java NC Server, and Java Server To O L K I T. S u n Releases 1 0 0% Pure J A V A Program to receive support from 100 companies. 1 99 January, S A S, etc. obtained J a V licenses. S u n delivers a perfect J A V A B E A N S development package, which is not completed within 8 months after determining its specification. 1 9 97, in February, S U N and A R M announced that J a V A O S can run on the R I S c processor architecture of A R M company. I N f O R M i X Company announced on its Universal Server and other database products to support JDK 1.1. N company announces its Netscape Communicator to support all J a V A-based applications and core A P I s. In March 9, 97, HP obtained Java WO R K S H O P license for the H P - U X operating system. Siemens A G Company, etc. obtained J a V license. Hitachi Semiconductor, I N f O R M I X Company, etc. obtained J a V A O S license. N o V E L L gets J a V AS T UD I O license. S u n Offers the JavaOS 1.0 operating system, which is a minimum and fastest way to run the J a V A environment on the microprocessor, and provide the J a V A O S license holder for S u n.

S u n Offers HotJava Browser 1.0, which is a J a V A browsing environment that can easily prepare dedicated information applications such as customer self-service tables and web applications on the company. S u n launched JDK 1.1.1.1 9 999 June, Sun Releases JDK 1.3 and Java Web Server 2.0.1.1.2 JavaBeans What is J a V A B E A N S? J a V A B E A N s is the reusable component technology of J a V A. The A SP is expanded by C O m, such as file uploading, E M A I L, and separating business processing or complex calculations to become independently reusable modules. J S P achieves the same functional expansion by J A V A B E A N. JSP provides perfect support for integrating Javabean components in web applications. This support not only reduces development time (can directly utilize test and trusted components, avoid repeated development), but also bring more scalability for JSP applications. JavaBean components can be used to perform complex computing tasks, or negative 2 first part JSP entry

Database interaction and data extraction, etc. During the actual JSP development, the reader will find that the JSP page will be very simple compared to the traditional ASP or PHP page. Since the J Ava B EANS is developing simple, it can take advantage of the powerful features of J ava language. Many dynamic page processing is actually encapsulated in J Ava B EANS. 1.1.3 JDBCJ D B C is a J a V A application interface for executing the S Q L statement, consists of a class and interface written in J a V A language, and JD B C will be used to access the database. J D B C is a specification that allows the database vendors to provide standard database access classes and interfaces for J a V A programmers, which makes it possible to make developments and products that are independent of the J a V A application of D b M s. The average J a V A development tool has a JD B C - O D B C bridge driver, so that as long as it is a database system accessible using O D b C, J D b C can be used. Interestingly, different from O Database Connectivity referred to as the Open Database Connectivity, J D b C is not an abbreviation of Java Database Connecivity, but the registered trademark of S u n, at least the official statement is like this. 1.1.4 The rapid development of J2EE e-commerce and information technology and its needs have brought new pressure to application developers. It is necessary to develop enterprise applications faster than earlier, less resources. In order to reduce costs, and speed up the design and development of enterprise applications, the J2EE platform provides a component-based approach to design, develop, assemble, and deploy corporate applications. The J2EE platform provides multi-layer distributed application models, components reuse, uniform security models, and flexible transaction control. Not only can you launch a creative customer solutions to the market faster than previously faster, and your platform is independent, and component-based J2EE solutions are not bound on any manufacturer's products and API. 1. The J2EE specification defines the following types of components • Apply a client component. • Enterprise JavaBeans Components. • S E R V L E T and JavaServer Pages Components (also known as web components). • Applet. A multi-layer distributed application model means that the application logic is divided into components based on the function, and these different components that make up the J2EE app can be installed on the same server or different servers. An application component should be installed where, depending on which layer of the application component belongs to the multi-layer J2EE environment. These layers are customer layers, WE B, business layer, and enterprise information system layer (EIS). (1) The client layer J2EE application can be web-based, or may not be web. In a web-based J2EE application, the user's browser runs in the client layer and the statics HTML page in a WE B server web layer or a dynamic HTML page generated by J S P or Servlet. In a web-based J2EE application, a stand-alone client does not run in an HTML page, but runs in other network-based systems (such as handheld devices or car), Applet programs, in the client layer Run and access Enterprise Beans without the Web layer. This is not the first chapter outline 3

WEB-based clients may also include a Javabeans class to manage user input and send it to the Enterprise Beans class running in the corporate level. According to J2EE specification, the JavaBeans class is not considered as components. The Javabeans class written for the J2EE platform has an instance variable and "GET and SET Method" for accessing data in the instance variable. The JavaBeans class used in this way is usually simple in design and implementation, but they must comply with the naming and design conventions listed in the JavaBeans specification. (2) The web layer J2EE web component can be composed of a JSP page, a web-based A P P L e t, and the S e R v L e t showing the HTML page. Calling S e r v l e t or the HTML page of the JSP page is packaged with the web component when the application is assembled. Like a client, the Web layer may include a Javabeans class to manage user input and send input to the Enterprise Beans class running in the business layer. The web component running in the client layer relies on the container to support such as a customer request and response and an Enterprise Bean query. (3) Business Code as a logic required to solve or meet the needs of a particular business area (such as bank, retail or financial industry) is executed by Enterprise Beans running on the business layer. A Enterprise Bean receives data from the client program, processes the data (if needed), and then send the data to the enterprise information system layer stored. A Enterprise Beans also retrieves data from the store and sends the data back to the client. Enterprise Beans running on the business layer depends on the container to provide a very complex system-level code such as transaction, life, state management, multi-threading, and resource storage pools. The business layer is often referred to as an Enterprise JavaBeans (EJB) layer. The business layer and the web layer together constitute the intermediate layer of 3-layer J 2 E E application, while the other two layers are the client layer and the enterprise information system layer. (4) Enterprise Information System Layer Information System Software Run Enterprise Information System Software, including enterprise infrastructure systems, such as enterprise resource programs (ERP), mainframe transactionProcessing, database system and other legacy information systems ( Legacy Informationsystems. J2EE Application Components may require access to enterprise information systems for some reason (such as access database). The future version of the J2EE platform will support the Connector architecture that connects the J2EE platform to a standard A P i on the enterprise information system. (5) Query Service Because the components of a J2EE application are run separately and often run on different devices, there is a need to query and reference other codes and resources. The client layer and the web layer code use the Java Names and Directory Interface (JNDI) to query user-defined objects (such as Enterprise Beans), environmental entries (such as a database drive position), JDBC Datasource for finding resources in the enterprise information system layer Object, as well as message connections. (6) Safety and transaction management such as security and transaction management can be configured on the Web and Enterprise Beans at the time of deployment. This feature separates the application logic from the configuration setting that may change. The J2EE security model allows you to configure a Web or Enterprise Beans component to allow system resources to access by authorized users. For example, a web component can be configured to prompt enter a username and password. An Enterprise Beans component can be configured to only call members in a particular community to call them.

Alternatively, a servlet component can be configured to enable a 4-Part 1 JSP entry organization to access certain methods while only allowing some of the privileges to access some of the methods. Also, the servlet component can be configured for another environment to enable everyone to access all of them, or only the selected minorities access all of them. The J2EE transaction model enables the relationship between methods that make up a single transaction when deploying, so that all methods in a transaction be processed into a single unit. This is what we want, because a business is a series of steps, all of which are all done, or all cancel. For example, an Enterprise Beans may have a group of methods that allow us to transfer money from the first account to the second account by borrowing and depositing the second account from the first account. We hope that all operations are treated as a unit, so that if it is faulty before the borrowing is deposited, the lending operation is canceled. Transaction attributes are defined on one component during assembly. This makes it possible to return a method from multiple application components to a transaction, which shows that we can easily change the application components in a J2EE application and re-specify transaction properties without having to change the code or recompile. When designing an application component, you have to remember that although Enterprise Beans has a mechanism that automatically initiates multi-step transactions, applets and applications may not support this. However, Applets and Application Customer containers can always call an Enterprise Beans that support this. It should also be noted that JSP pages and servlets are not designed to be transactions, and they should usually hand over transaction to an Enterprise Bean to complete. However, if the business is required in a JSP page or a servlet, then this kind of work should also be very limited. (7) Reusable Application Components J2EE Components (Applets, Applications Customer, Enterprise Beans, JSP Pages, and Servlets) are packaged into modules and delivered as a Java Archive (JAR) file. A module consists of related components, related files, and describes how to configure components. For example, in the assembly process, an HTML page and servlet are packaged in a module, which contains HTML files, servlet components, and related configuration description files, delivers in the form of a Web Archive (WAR) file, which The file is a standard JAR file with a .war extension. The use of modules makes it possible to assemble different J2EE applications with certain components in the same component. For example, a J2EE application's Web version may have an Enterprise Beans component, as well as a JSP page component. The Enterprise Beans component can be combined with an application client component to generate non-Web versions of the application. This doesn't need additional coding, just an assembly and deployment. Moreover, the reusable assembly makes it possible to divide the application development and deployment process into a different role, so that different people can complete different parts of the package and deployment process. 2. The J2EE platform defines the following roles: (1) J2EE product provider design and makes J2EE platforms, APIs, and other features defined in the J2EE specification can be purchased by other companies or people. (2) Application component provider creates a company or individual for web components, Enterprise Beans components, applets, or application clients for J2EE applications. During assembly, apply component files, interfaces, and classes to be packaged into a JAR file.

(3) Application assembly obtains the application component JAR file from the component provider and assembles them into a company or individual of the J2EE application Enterprise Archive (EAR). This file is a standard file with the EAR extension. . Application assemblaborators provide the overall information related to the application and use the verification tool to verify the contents of the EAR file. Unit and deploy information first chapter summary 5

Stored in a text-based configuration description file, this file uses an XML tag to mark the text. Application assemblists can edit the configuration description file using a assembly and configuration tool that can properly add an XML tag with an interactive selection. (4) Deployment Commercial Deployment (D E P L E) J2EE Application Company or Person. The responsibilities include setting transaction control, security properties, and indicating that an Enterprise bean is handling their own storage according to the instructions provided by the application component provider, or by a container. Deployment involves configuration and installation. During the configuration, deployers follow the instructions provided by the application component provider to solve external dependence issues, define security settings, and assign transaction properties. During the installation process, the deployment installs the application component to the server and generates a specific class and interface of the container. (5) System administrator configures and manages the calculation environment and network infrastructure running J2EE applications, and supervises people who operate the environment. (6) Tool providers produce companies or individuals that are used to develop, assemble, and packaged tools for development, assemblers, and packages. (7) Design User Interface and Engine When designing user interfaces and backend engines for J2EE applications, it is necessary to decide to make the program based on WE B or not WE B. When making this decision, we may want to consider platform configuration, speed, security, network traffic, and network services. For example, an applet containing a user interface and is often accessed by a large number of users may take a long time to be down, which makes users depressed. However, if you know that this A P L e t is to run in a controlled environment in a company's internal network, then in this case, the applet will have a fully acceptable speed. Another consideration is that wherever the heavy processing should be executed. For example, if the client executes in a cellular phone or player, the server should complete as much as possible calculations and data processing, and the client program should only display the result. However, large financial analysis systems that are designed to run on a powerful desktop platform should complete their complex calculations on the client. Applying client programs and A P P L e t user interfaces are usually created with Swing API, which can be obtained from the standard JA V 2 platform. The Swing API provides a set of GUI components (tables, tree structures, buttons, etc.) that can be used to implement a more interactive experience than using a typical HTML page. Swing also supports HTML text components, which can be used to display responses from one server. The client can access the Enterprise Beans layer or the enterprise information system layer. But this procedure should be realized with caution. The program bypassing the EJB layer can use the JDBC API to access a relational database, but should be limited to management tasks for maintenance of the database form. (8) Designing web-based applications based on web-based applications are browser-based, and if they run on i n t e R n e t, they may be accessed by people around the world. When designing a web-based application, not only do you need to decide what to use to handle content and application logic (HTML, XML, JSP pages, and S E R v1), and should also consider internationalization of the application. An internationalized web-based application provides users with a language that loads the application of the application based on the selected language. For each language that is supported, the application body is stored in an external file and corresponds to the keywords of another file. Application code uses these keywords and selected languages ​​to load the correct text. Internationalization API also provides classes to format dates and money according to selected languages. Once the details of the internationalization of the application can be established, you can decide what 6 of the first part JSP entry

To achieve it. In general, a web-based application uses HTML to display data; use XML to define data to make it read and processed by another program; use JSP pages or s ervlet to manage users and business layers or storage layers The data stream between. There are four kinds of web-based applications that can be implemented on the J2EE platform. From simple to complex arrangements, they are: • b Basic h t m L. • B with basic JSP page or servlet's H t m L. • B with J S P pages with Java Beans classes. • B uses the application logic according to the functional score into the highly structured application of the region. When designing a web-based application, you need to decide what to use to create it. If it starts from building a simple application, and think it will add a function to the application in the future, then the design should adapt to future development needs. (9) Model, view, and controller architecture In the case of a component-based J2EE platform, the remaining issues may be how to organize applications to implement simple and efficient application upgrades and maintenance, and how to make The person who knows the program code avoids the program data. The answer is in the use of models, views, and controller architecture (MVC). The architecture such as MVC is a description of the problem and its solution design, but each problem is reproduced, the solution will not be exactly the same. The MVC design paradigm includes three objects: Model provides application business logic (Enterprise Beans); view (view) is displayed on the screen (HTML page, JSP page, Swing GUI); controller is servlet , JavaBeans or Session Beans class, which is used to manage the interaction of users and views. We can imagine the controller between the view and data, and manage the view to interact with the model. The front-end client can be easily replaced by making the view completely independent of the controller and model. Also, by maintaining the controller and the model code in the view, those who don't understand these codes cannot change what they should not change. Separating the controller and model can change the controller without affecting the model, or the model can be changed without affecting the controller. For example, if the front end of the application is an HTML page, HTML experts can update it. If you use a J s P page, place the controller's code in a JavaBeans or SESSIONBeans class, or use the action tags, so that the JSP page contains only JSP code. This book will explain how to use J 2 E e to establish an enterprise-class WE B application in the second part. 1.1.5 EJBE J B is the earprise javabeans mentioned earlier. The distributed application of the upper layer of e j b is based on the object component model, and the low-level transaction service uses A P i technology. E J b technology simplifies the development, configuration and execution of enterprise application systems written in J ava language. E J b The architecture specification is developed by Sun Microsystems. E J b technology defines a set of reusable components: Enterprise Beans. These components can be used to establish a distributed application like a wooden. When you write the code, these components are combined into a specific file. Each file has one or more Enterprise Beans, plus some configuration parameters. Finally, these Enterprise Beans are configured to a platform installed with the E J B container. The customer can pass through the HO M e interface of these B E A N s, positioned to a BE A N S, and generates an example of this BE A N S. In this way, the customer can call the application method and remote interface of B E A N s. Chapter 1 Overview 7

E J b Server acts as a bridge of the container and low-level platform, manages E J b containers and functions. It provides the ability to access the system service to the E J b container. For example: the management of the database and the management of transactions, or other E N T E R P R I SE's application servers. Enterprise Beans in the J2EE application When writing a J2EE application for administrative specific business features (such as tracking employee materials or complex financial calculations), the business logic to complete these tasks is placed in Enterprise Beans in the EJB layer. In this way, you can focus on solving your business problems in your hand, and use Enterprise Beans containers to support low-level services, such as status management, transaction management, thread management, remote data access, and security. Separating business logic with low-level system means that the container can create and manage Enterprise Beans at runtime. Any Enterprise Beans written in accordance with the specification can be configured in accordance with how they will be used in a specific J2EE application, and can be deployed to any container compatible with specifications. Reusable components make it possible to change and recompile Enterprise Beans code. An Enterprise Beans consists of interfaces and classes. The client accesses the Enterprise Beans by Enterprise Beans Home and Remote Interfaces. The HOME interface provides methods for creating, deleting, and locating Enterprise Beans, while remote interfaces provide business methods. At deployment, the container is created by these interfaces to enable customers to create, delete, position, or call business methods located on Enterprise Beans. Enterprise Beans provides an implementation of business methods, creating methods, and query methods. If Enterprise Beans manage its own persistence, it also provides its life-actions. There are two Enterprise Beans: Entity Beans and Session Beans. A session beans represent a short session with the client program, and may perform database read and write operations. A session beans may call J D b C themselves, or it might use Entity Beans to complete this call. In this case, this Session Beans is the customer of the entry Beans. The domain of a session beans contains session and is short. If the server or client crashes, the session beans are lost. This mode is usually used on database programming languages ​​like PL / SQL. An Entity Beans represents data in a database and method for which the data is applied. In the employee information table in a relational database, each line has a beans to represent. Entity Beans is transaction and is long life. As long as the data is left in the database, Entity Beans exists. This mode can be easily used for relational databases, not just object databases. The session beans may be stateful or stateless. A stateful Session Beans contains a session status of the client. This session state is the domain value of the session beans instance plus all objects referenced by these domain values. There is a status session beans that does not represent data in a persistent data store, but it can represent and update data on behalf of the client. The stateless session beans do not have any status information for a particular client. They are often used to provide server-side behavior that does not maintain any particular state. There is no status sessionBeans requires fewer system resources. A business object that provides a general service or a shared view for indicating the stored data is an example of stateless session beans.

Because Enterprise Beans takes a considerable system resource and bandwidth, you may want to configure some business objects to access objects or value objects. Data Access Objects Complete jobs such as representing the client access database. Value objects are used to represent a structure of the data field and provide a simple "GET and SET" methods to access these data. Additionally, the program can be configured to use Enterprise Beans to undertake the tasks between the client and the EJB layer. Enterprise Beans for accessing relational databases using container management persistence, does not require Getting Started at the first part of B E A N S8

Use any JDBC 2.0 API in the code to perform database access because the container completes these work. However, if you use Beans management persistence, or to access a non-relational database's enterprise information system, you must provide the corresponding code in B E A N s to complete these work. In the case where Enterprise Beans uses Beans management persistence to access a database, you must use the JDBC 2.0 API code to implement the life-life method of the Enterprise Beans to handle loading and storage, and running at system and persistent data storage. Maintain data consistency between data. An Enterprise Beans that use Beans managed, or a web component that needs to access the enterprise information system must provide the appropriate code. These code may be a JDBC 2.0 API for database access; or an enterprise information system API for accessing a specific enterprise information system; or an access object for abstract enterprise information system API complexity and low-level details, Or a connection object for accessing the enterprise information system resource. Although the web layer uses HTTP or HTTPS to transfer data between the layers, the EJB layer is used by R m i - i i o P. RMI-IIOP is a complete distributed computing protocol that allows any client-layer programs or web layers that access Enterprise Beans directly access the EJB layer. These services include JAVA Message Service (JMS) for finding and reference Enterprise Beans, Java Message Service (JMS) for sending and receiving asynchronous messages, and J D b C for relational database access. 1.1.6 Java ServletJava Servlet is the basis of J s P technology, and the development of large WE B applications requires Java Servlet and J S P. to complete, and the knowledge of S E R V L e t will be described in the second part of the second part. S e r v l e t This name is probably from a P P L e t, and now there are many domestic translation methods. In order to avoid misunderstanding, this book decides to use S E R v L E T without any translation, readers can call it "small service programs". SERVLET is actually the same as traditional CGI programs and ISAPI, NSAPI, and other WE B program development tools. After using Java Servlet, users do not have to use CGI mode with low efficiency, and do not have to use only a fixed We. The API mode running in the B server platform dynamically generates the WE B page. Many WE B servers support S E R V L E T, even if the WE B server that does not directly support S E R V L E T can also support S E R V L e t by additional application servers and modules. Thanks to the cross-platform characteristics of J a V A, S e r v L e t is also a platform-independent, in fact, as long as the Java Servlet specification is compliant, S e R V L e t is a full platform and the WE B server is independent. Since the Java Servlet is available in a threaded manner, it is not necessary to start a process for each request, and the multi-thread mechanism can be used for multiple request services at the same time, so Java servlet is very efficient. However, Java servlets are not shortcomings, and the traditional CGI, ISAPI, NSAPI mode. Java servlet is the use of output HTML statements to implement dynamic web pages. If you use Java Servlet to develop the entire website, the integration process of dynamic parts and static pages is simply It is a nightmare.

This is why S u n is also launched by Java Server Pages. 1.2 JSP technology said before, the biggest disadvantage of Java Servlet is that there is no separation of the logic of the website and the page of the page, causing the entire S e R v L e t code confusion. In order to solve this disadvant of Java Servlet, S U N introduces Java Server Pages-J s P. 1.2.1 JSP Technical Overview According to the scripting language is the language of serving a subsystem, JSP should be seen as a scripting language, however, as a scripting language, JSP is too powerful, in JSP Almost all J AVA classes can be used. Chapter 1 Overview 9

As a text-based, the J S P provides all the benefits of the Java Servlet, and when combined with a JavaBeans class, a simple way to separate the content and display logic is provided. The advantage of separating content and display logic is that the person who updates the appearance of the page does not have to know the Java code, and the person who updates the J ava b EANS class does not have to design the web page home hand, you can define the JSP page with JavaBeans class. Web Template to create a website consisting of a page with similar appearance. The JavaBeans class completes the data, so there is no Java code in the template, which means that these templates can be maintained by an HTML writer. Of course, you can also use Java Servlet to control the logic of the website, and use the Java Servlet to call the logic and content of the website to separate the site. This chapter we will make some more in-depth descriptions of the logic and content of this separation site. When choosing a Java Servlet, or a JSP page, you have to remember that Java Servlet is a programming tool that best applies to low-level application features that do not require frequent modifications; and JSP pages are centered on display Descriptive methods combine dynamic content and logic. For simple web-based applications using a JSP page, custom tag or S C R i P L e T can be used, rather than using the JavaBeans class to combine content with application logic. Customized tags are packaged into a tag library and are introduced into a JSP page. S c R i P L e t is a small J a V A code segment that is directly embedded in the JSP page. In general, in the actual J S P engine, the J S P page is compiled when executed, not explanatory. Explanatory dynamic web development tools such as ASP, PHP 3, etc. have not met the needs of current large-scale e-commerce applications due to speed, and traditional development technologies change to compilation, such as ASP → ASP ; PHP 3 → PHP 4. Although the JS P engine does not require the actual J S P engine to use the compilation execution method, it is estimated that the J s P page is not performed using the explanation. In general, the J s P page is generally translated into a J a V A source file for S E R V L e t, and then compiled into a C L A S s file of S e R V L e t through the J a V A compiler. Why should I compile S E R v L e t? It is said that it is said that the original S E R V L e T engine can serve J S P directly, and the J S P engine only needs to translate J S P translated into S e R V L E t. It should be noted here that the J S P Specification does not specify how to translate the J S P p-page into S E R V L e t, therefore, the results of different J S P engine translation are also different. After the JSP file is translated into S Ervlet, each client (usually the user's WE B browser) requests this JSP file to the server, the server will check if the JSP file has changed since the last compiled, if there is no change It is directly executed directly, and it is quite high if you don't have to recompile it. In general, the compilation of JSP files occurs when the first user accesses this JSP page, and this first user is usually the developer himself, so that it is officially put on the server to let users access JSP files. Have a corresponding compilation SERVET.

Many servers have settings, which allows the J s P file to be pre-compiled before the first user access, this seems, the efficiency is higher. Later, in Chapter 4, the SE R V L E T in which a simple J S P P file is shown. In the JSP specification, there is no clear request of the program code part in JSP (called S Criptle), be sure to write with J ava, in fact, some JSP engines are other scripting languages, such as: EMAC - S Cript WE B L, etc., but in fact these scripting languages ​​are also built on the J ava, compiled into SERVLET. According to JSP specification, there is no relationship with JSP, but because the powerful function of JSP is mainly working with J Ava B Eans, Enterprise JavaBeans, even the Scriptlet section does not use Java, compile The resulting code should also be related to Java. 1.2.2 JSP's advantages and comparisons compared to other WE B development tools compared to traditional C G i, J S P has considerable advantages. First, on the speed, the traditional C G i program needs to use the system 10 first part JSP.

Standard Input Output Device To achieve dynamic web pages, while J S P is directly associated with the server. Moreover, for C G i, each access requires a new increase in processing, the process constantly establishes and destroying a computer that will be a computer as a WE B server will be a small burden. Second, J S P is designed specifically for WE B, and its purpose is to establish a WE B-based application that includes a set of specifications and tools. Using J S P technology can easily combine a large heap J S P p-page into a WE B application. Compared with IS PA I and NSAPI, JSP has a much faster development speed. The development is also much smaller. After compiling into J avas ervlet, the latest Just (Just In Ti ME) J ava explanation is compiled. The execution speed is also slow. Moreover, the technique of I S A P i and N S A P i and the WE B server is too closely combined with an error in use, it is easy to crash the WE B server, while J s P does not have this shortcoming. The true opponents of J S P are A S p and p h p, as well as the upcoming A S P , comparison with A S P, P, P, and J S P in WE B technology, see Table 1 - 1. Note: The A S P 3.11, J S, refers to a specification, which is pointed out in J S P 3. Table 1-1 ASP, JSP, PHP comparison ASPJSPH PWE B Server IIS, PWS, etc. A Pache, IIS, PWS, Netscape Server, etc. Wi NDOWS, etc. Wi NDOWS, etc. Wi NDOWS component technology COM, J ava b elens Custom TA G syntax No open-free unspeakable free software scripting language support VBS CRIPT, JS CRIPT, etc. PHP to establish large WE B applications, etc. Waiting for very fast learning difficulty, low S Ession management has a unified database connection, ADO, ODBC, etc. ASP, etc., PHP, PHP 3, PHP S1. WE B server and run platform ASP is currently only supported by Microsoft Internet Information Server (IIS) and Personal Web Server (PRSONAL Web Server (PWS), since IIS and PWS have only version of Wi NDOWS, the ASP can only be used under Wi NDOWS platforms. Although there is a third-party plug-in to use A S P in U N i x, it can only be a "toy" under the U N i x platform supported by C O m based on the C O M component technology. J S P is just a specification, although the J S P is generally implemented by J S P generally uses J A V A, but as a cross-platform language, J A V A can be used under many platforms. In this way, J S P will also be obvious to cross-platform. Current Chapter 1 Overview 11

Wait a Pache, IIS, PWS, Netscape Server, I P Lanet, etc. Various UNIX (s OLARIS, L INUX, AIX, IRIX, etc.), Wi NDOWS, M AC OS, etc. J ava b elens, EJB, etc. Home cooperation, including Sun, IBM, BEA We blogic, N etscape, o racle, etc. JS PJ SP, etc., etc., etc. Used under a variety of WE B servers and operating systems. Such as Apache Web Server and Microsoft IIS, etc. Apache Web Server is the world's highest Web server product, which can be run in many operating systems including Sun Solaris, I B MA I x, SGI Irix, L i n u x, and Wi N D O W s. The implementation of J S P under Apache Web Server can be achieved by free Apache JServ and G N u J S P, J a K A R T A - To M C A T, can also be implemented using the commercial J R u N (L i V E S O f T W a RE), WE B L O G i C (B E A), WE B S P HE E R E (I B M). Microsoft IIS itself does not directly support J S P, but can be implemented by J R u n, WE B L O G i C, WE B S P H E R E. You can also use the application server to add J S P supported Netscape Enterprise Server and can directly support J S P's IPLANET Web Server, etc. PHP itself has supported various operating systems and WE B servers. PHP can be directly compiled into a Pache as an additional module of a Pache. Since a pache supports multiple operating systems, PHP can also be Implementation on various operating systems. P h p can also be inserted into I I s or P W s. 2. Component Technology A S P and J S P Support for Component Technology has been perfect, and P h p is until it is until it will begin to support C O m and J A V A B E A N s. However, support is not very perfect. If P h p cannot improve the support of component technology in the future, it will be difficult to compete with J S P and A S P in large WE B applications. However, due to the easy-to-use use of PH P technology itself, plus numerous functions support and open source characteristics, P h p will still have a place in the development of small and medium WE B sites. In fact, J S P itself has no significant advantage of A S P and P H P, and the power of J S P is because of its strong J a V A technology behind it. J a V A technology, including J a V A B e a N s and J 2 E E technology, is a powerful vitality of J S P. M i C R O S O f T The latest A S P technology has many exciting advances compared to A S P technology, but from the perspective of enterprise applications, J S P technology still has considerable advantages. There is reason to think that in future WE B development, the small and medium-sized site will appear in the three-minute world, but for large e-commerce sites, J S P and J 2 E e technology will become preferred.

1.3 Several main ways of developing WE B using JSP as part of J 2 EE, can be used to develop small WE B sites, or to develop large, enterprise-class applications, this section will tell for different The scale of the WE B system uses JSP to develop different ways. 1.3.1 Directly use J S P For minimal WE B site, you can use J S P to build a dynamic web page. This site is the most simple, and it is only a simple message board, dynamic date and other basic functions. For this development mode, all dynamic processing portions can generally be placed in S C R I P L e t of J S P, just like the PH-Page is developed using P H p or A S P. 1.3.2 JSP JavaBeans Medium Site is facing database query, user management, and small amount of business logic. For this site, all things cannot be handed over to the J s P page. Joining J a V A B e a N S in a simple J S P will help the development of this medium-sized website. Using J A V A B E A N s, it will be easily completed, such as database connections, users log in and login, and commercial business logic package. Such as: Connect commonly used databases is a Java Beans, which is convenient to use, but also make J S P files simple and 12 first part JSP is clear. By packaging, it is also possible to prevent general developers from obtaining the database control. The first part of this book will mainly tell this development method. In Chapter 2, it will briefly tell how to develop J a V A B E A N s, and readers do not have to worry about J a V A B E A N s. 1.3.3 JSP JavaBeans Servlets Develop a dynamic website with A S P or P h p, has long been a more important issue, which is the logical relationship of the website and the display page of the website is not easy to separate. Often you can see some mixed IF...............................} And a large number of displayed HTML code ASP, PHP page The programmer of a good program writing habits, and its work is almost unable to read. On the other hand, the developers of dynamic We b are also complaining, and the static page and dynamic procedures for website art design are an abnormal pain process. How to solve this problem? After j s, a friend of the author thinks that S e R V L e t can be replaced by J s P, however, the fact is that S E R V L e t will start the task that determines the logic flow of the entire site logic process after the task is not responsible for the dynamic page. In a website that is abnormal logically, with the help of SERVET and JSP good interaction relationships and J Ava B EANS assistance, you can put the entire logical structure of the website in the S Ervlet, and put the output of the dynamic page in JSP The page is completed. In this development method, a website can have one or several core S e R v L e t to handle the logic of the website, and complete the client (usually a WE B browser) request by calling the J s P page. Later, we will be able to see that this function of S e r v L e t is replaced by e j b in the J 2 E E model. 1.3.4 J2EE Development Model In the J 2 E E development model, the entire system can be divided into three main parts: 1. The view view is the user interface part, and the WE B application is H T M L, X m L, J S P pages. This part mainly handles the things you see, and the dynamic J S P section processes the dynamic webpage you can see, and the static web page is output by H t m L, X m L. Figure 1 - 1 Chapter 1 Overview 13

2. Controller. The controller is responsible for the entire logic of the website. It is used to manage user interactions with views. You can imagine the controller between the view and data, and manage the view interact with the model. By making the views completely independent of the controller and model, it is easy to replace the front-end client, that is, web generators will be able to alter the WE B page independently without worrying about impacting the functionality based on WE B-based applications. In J 2 E E, the function of the controller is typically taken by S e s S I O N B E A n in SE R V1 E T, J A V A B E A N S, Enterprise JavaBeans. 3. Model model is the application business logic part. This part of the main role is Enterprise JavaBeans, with the help of e j b powerful component technology and enterprise management control, developers can easily create reusable business logic modules. Figure 1 - 1 illustrates the relationship between the above three in the J 2 E E development model. 1.4 This book is used by the software and acquisition method 1. JDKJava Development Kit is a J a V A development kit, and J S is developed must have J D K. This book uses version 1. 3, which can be found in H T T P: / / J a V a. S U n. C O m. Similarly, in the home page of S u N, you can find a Chinese document of J D K, and readers may feel more convenient to use localized documents. 2. JAKARTA-TO M c A Tapache Jakarta project group developed J S P Engines based on the JD K, which can build a simplest J S P test platform. Open source, easy to use, the disadvantage is not to support J 2 E E technology, and E J B cannot be used. Address: H T T P: / / J A K A R T A. A P A C H E. O RG. It should be noted that the developer of the original GNUJSP project is now fully turned to the J Akarta - To McAT project, not recommended to build a Pache JS ERV GNUJSP to build a JSP platform, if you must use, you can also be in http: / / / wwwwwww W. a pache. O RG Find the software you need. 3. Apache Web Server Just use To McAT to build JSP utility platforms, general small sites use JSP to use a Pache to McAT mode, because as independent web server, TO MCAT efficiency is obviously not enough, Nor a numerous practical features of A Pache. Apache Web Server can also be in H t t p: / / / w w. A p a c h e. O RG. 4. J2SDKee can find Javatm 2 SDK, Enterprise Edition development tool called J 2 S D K E E on the homepage of S u N. Use J 2 S D k E E to obtain a development platform for J 2 E E with minimal overhead. Address: H t t p: / / / j a v a. S u n. C O m / j 2 e e. 5. IBM We BSphere To develop WE B applications based on J 2 EE technology, it is best to use a commercial application server (a PPLicatio NS ERVER), IBM's WebSphere is more useful as application servers in China. There are also many documents and examples, and it is more convenient to learn. I B M offers a free trial version that can be found on I B M's homepage.

I B M has also released a lot of disc try on the DV version in China, and there are also in major F t P sites. 6. BEA WE B L O G i C14 Part 1 JSP Getting Started

As the industry-leading application server provider, the BEA We blogic application server is far ahead of other opponents, but the use of the BEA We blogic application server is greater than IBM We bsphere, and the document is almost English, Domestic readers may feel more difficult. The address of the trial version of the BEA WE B L O G I C applied servers on the home page of B E A S Y S is. H t t p: / / / / / / / w. b e a s y s. c o m or h t t p: / / / / w w. WE B L O g i c. C O m. 7. UltraEditu LTRA E DIT is not a J ava tool, but the author thinks it is a better JSP writing tool, you can get the trial and support for the U LTRA E DIT on the homepage of U LTRA E DIT. J AVA 2 and JSP The syntax file address is. H t t p: / / / / w w. U L T R A E D i T. C O m. Readers can also learn from other JSP engines, such as LiveSoftware Jrun, Inprise Applications ERVER, SERVLET E Xec, etc., there are also many good J ava development tools and text editors to use, such as: I NPRIS EJBUILDER 3.5, IBM Virsual Age for Java, Symantec Virsual Café, E DIT P LUS, J AVA P AD, etc. Finally, the code writing specification of this book: Class Name: When the class name is composed of several words, these words are close to, and the first letter of each word is overrout. Others: The first letter lowercase of the first word. Each block is uniformly indented into a TA B tab. However, for the code segment of the long code, uniformly cancel the indentation. Note is listed separately as a row. Each line code length does not exceed 6 0 characters (for the need to publish). Such as: Class testclass {Int a; void testfuncs () {...}} first chapter outline 15

转载请注明原文地址:https://www.9cbs.com/read-3343.html

New Post(0)