[IT168 Special Article] We know that JSP (JavaServer Pages) is a dynamic web page technology standard. Servlets are Java technology's answer to CGI programming.
There are many WEB servers that support JSP/Servlet. Choosing a suitable WEB server is very important for building a JSP website. The more famous WEB servers include: Allaire JRun, Apache Tomcat, BEA Weblogic Application Server, IBM WebSphere Application Server, iPlanet Web Server, JavaServer Web Development Kit (JSWDK) and Java Web Server, etc.
When building a JSP website, JSWDK can be used as a WEB server for learning and debugging. Generally, small and medium-sized websites can use Apache+Tomcat as the WEB server. Large enterprise-level websites can use IBM WebSphere Application Server, BEA Weblogic Application Server and SUN iPlanet Enterise. Web Server, etc. serve as WEB servers.
1. Use JSP directly
For the smallest WEB site, JSP can be used directly to build dynamic web pages. For this development model, all dynamic processing parts can generally be placed in JSP scriptlets, just like PHP or ASP are generally used to build dynamic web pages.
2. JSP+JavaBeans
Medium-sized sites face database queries, user management and a small amount of commercial business logic. Adding JAVABEANS technology to JSP will help the development of this medium-sized website. Using JAVABEANS, it will be easy to complete tasks such as database connection, user login and logout, and commercial business logic encapsulation, as shown in Figure 1.
Figure 1 |
3. JSP+JavaBeans+Servlet
When using ASP or PHP to structure a dynamic website, there is a logical relationship between the website and the display page of the website that is not easy to separate. In a website with extremely complex logical relationships, with the help of the good interaction between Servlet and JSP and the assistance of JavaBeans, the entire logical structure of the website can be placed in the Servlet, and the output of the dynamic page can be placed in the JSP page. In this development method, a website can have one or several core Servlets to handle the logic of the website, and complete the request of the client (usually a WEB browser) by calling the JSP page. In the J2EE model, this function of Servlet can be replaced by EJB, as shown in Figure 2.
Figure 2 |
4. J2EE development model
In the J2EE development model, the entire system can be divided into three main parts (as shown in Figure 3):
Figure 3 |
* Controller. The controller is responsible for the entire logic of the website. It is used to manage user interactions with views. In J2EE, the controller function is generally performed by SessionBeans in Servlets, JavaBeans, and Enterprise JavaBeans.
* Model. The model is the application business logic part. The main role of this part is Enterprise JavaBeans. With the help of EJB's powerful component technology and enterprise-level management control, developers can easily create reusable business logic modules.
The website operating system built by JSP can choose Unix, Linux or Windows platform. The Web server can be commercial or use free server software such as Apache and Tomcat. The back-end database can choose Oracle, Sybase, DB2 or Informax, MySQL, etc. according to the actual situation. .
Both Apache and Tomcat can be used as independent WEB servers. Apache is powerful and efficient, but it does not support JSP and serlets. Tomcat is a JSP Server jointly developed by Sun and Apache. Tomcat has now become Apache's main Servlet and JSP engine. Tomcat is designed to be executed as an independent server, unlike Jserv which is attached to Apache, so that it can exert its capabilities in servlets instead of HttpServlet. Tomcat is a Java program, so as long as you have a JDK, you can use it without considering the operating system platform.
As a WEB server extension, the Tomcat server has some issues that need to be explained: Tomcat is not as fast as Apache when processing static pages; Tomcat is not as configurable as Apache; Tomcat is not as powerful as Apache. Based on the above reasons, a real website uses an Apache as a web server to serve the website's static page requests; and uses the Tomcat server as a Servlet/JSP plug-in to display the website's dynamic pages.
Using a structure like apache+tomcat has more outstanding advantages, mainly reflected in better scalability and security. The main feature of this type of site is that each page may be dynamically generated, but the main part of the data is still static (for example, various images GIF, JPG, PNG, streaming media, etc.). This structure The advantage is both scalability and security.