The development of Java Web technology has gone through the following stages:
L Servlet technology; l JSP technology; L model 1: JSP + javabeanl Model 2: JSP + JavaBean + servletl framework l visual development are described below respectively.
Servlet technology stageServlet is the earliest web solution in Java technology. It is very similar to the compiling of common Java classes. Using Servlet technology, all information on the page must be generated using the output statement. The content of the page generated by the following code (some code) is "helloworld !". Public void doget (httpservletrequest request, httpservletresponse) throws ioexception, servletexception {response. setcontenttype ("text/html; charset = gb2312"); printwriter out = response. getwriter (); out. println ("<HTML>"); out. println ("JSP technology stageThe goal of JSP technology is to quickly develop websites and embed Java code into webpages to complete the website. For example, the following code is a simple JSP Example: <HTML> Model 1: JSP + JavaBean stageJavabean is a component written in Java. It is easy to understand and can be considered as a special Java class. JavaBean encapsulates the processing process on the website. The result is that in the JSP file, only the input and output functions and control functions are provided. The processing process is placed in JavaBean, then, call the JavaBean function in JSP. JSP provides several tags to support calling. The following example shows this model. JavaBean file: package test; public class printmessage {Public String print () {return "JavaBean return information";} page file: <% @ page import = "test. * "%> <JSP: usebean id =" printmessage "class =" test. printmessage "Scope =" request "/> <HTML> Model 2: JSP + JavaBean + servlet stageIn Model 2, control functions in JSP are extracted and implemented using Servlet. In this way, JavaBean emphasizes functions, and servlet is mainly used for control. The JSP and Servlet functions are the same, but JSP focuses mainly on tags (HTML tags and JSP tags), and servlet is Java code. Both the JavaBean and Servlet are Java code, but the servlet can receive requests and users can access them directly. The JavaBean cannot receive requests and must be called by JSP or servlet. Features of this model: JSP mainly uses HTML tags and JSP tags to complete input and output. Servlet mainly controls, receives requests, calls business processing (JavaBean), and finds a JSP page to respond to users based on the call results. JavaBean completes all the processing. This method is actually used by the MVC mode. The MVC pattern consists of three parts: M representing the model (simulating real things), which is mainly used for processing the process; V representing the view, which is actually the input and output functions; c Representing the controller, the process of the main control program.
Framework phaseWith the development of Java Web application technology, a large number of frameworks have emerged, including the web layer framework and the persistent layer framework. The web layer framework usually provides some general functions for Web applications. When writing an application, you only need to pay attention to something special. For example, Servlet functions completed as a controller include obtaining user input information, verifying and converting information, and calling business logic using this information (JavaBean method ); then select the interface to respond to the user. If you set the obtained information to a variable, configure the verification and conversion to be performed, configure the method to be called, and configure the interface to respond, the servlet can be used. The second part of this book introduces the popular web layer frameworks struts2 and JSF, and implements a simple framework. The persistence layer framework is mainly used to solve database access problems. It also extracts common content for database access and only writes special things when writing applications. For example, to add user information and book information to a database using JDBC technology, the difference between the two sections of code is that the table names are different, and the correspondence between columns and attributes is different. The persistence layer framework can complete the Add project. You only need to provide the table name and the ing between columns and attributes. The second part of the persistence section describes the persistence layer framework.
Visual DevelopmentWith the enhanced support for Web applications in the integrated development environment, Visual Web Application Development (JSF technology) should be the future development trend. Development in this way is as convenient as developing applications in C ++ builder or VB. Last Lecture: 7. servlet operating principles next lecture:
9. Web application configurationLi xucheng csdn blog: Why? U= 124362 & C = 7be8ba2b6f3b6cc5