b/S system is browser/server, browser/server system, that is, customers in the browser operation, and code implementation of the specific processing and database operations, and so on, by the background server to complete, delved, action very huan. For example, we query the results, we enter personal information through the browser, and send personal information to the backstage, backstage to obtain your information to do a series of processing and from the database to identify your scores, inscrutable, and finally return to the browser page, display in your eyes, this is the typical B/s system.
and the browser to show the static page, we call HTML(Hypertext Tag language), in fact, the so-called hypertext, it is the text, it is the same as Doc,txt, but its super place is that it will openly put information in front of you, you open a Web page, Different parts have different colors, buttons, patterns, you can choose, you can enter, single selection, check, head is the head, tail is the tail, this is the HTML super place. It actually divides a page into different parts. For example, you want to write the head of the text in the <HEAD>, the content written in <BODY>, if a page is divided into different frames, each frame written in <frame> and so on, each other, to complement each other. Another example, it defines a lot of tags, with <span>, <div> separate each small piece of content, you can enter the text label <input>, select the item label <select>, Button label <button> Wait a minute.
The browser side is the customer to enter and view, and by the server specific processing, in the javaweb is handled by the servlet container . It's actually an organized, disciplined Java program. The client input some information through HTML (such as the number), the servlet will get your number through the HttpServletRequest object, and then call other program processing (with the school number to the database query, find your score back to the servlet), the servlet to get the results, Pass it to the HttpServletResponse object and return it to the foreground page, one go, methodically. Of course, if the servlet can't handle your request, it will forward your request to another servlet (using RequestDispatcher to forward), and then another servlet to handle it.
Sometimes, such as you log on to a page, each visit need to re-login, more trouble, and the browser and the servlet reached a tacit understanding, collusion out a call Cookie(cache) of things, put the cache to the client, if you log in the second time, the system will read the cache, Directly extract your user name and password, you do not need to enter, of course, in addition to login, other browsing information can be put into the cache. However, because the cache is placed on the client, that is, stored on our computer, it is not possible to store large information, difficult to use, then the session will be used, it will save a lot of data on the server side.
Back to the browser side, HTML can not just dry black and white text box, need to the various parts, what is the color of the button, where the picture is placed, how big the input box, these things need to decorate, and the decoration tool is CSS(learning name: Cascading style form), You can take out every part of the HTML, use CSS to paint it, oil, wax, etc., joy, lifelike. And, HTML can't heaven, you enter your number in the browser, you need a medium to pass it to the servlet. This media is the submission of the <form> form. That is, you write the information you want to transmit in <form>, and then send the message back to the background by submitting it (such as the Submit button).
Each time you want to query a message, pass the input criteria to the background servlet, and then return the servlet search results to the Web page, the page refreshes and the information you want is displayed. But sometimes you do not want to refresh, such as you are looking at an advertisement or other modules, a refresh, is looking at the things are gone, back to the original state, laughing, Qiang oars ashes. This is where Ajaxis used. Use it to submit conditional information, when the background returned results, do not need to refresh, you can display the information to you invisibly, without affecting the other content you are viewing, big sound, the elephant invisible, with quiet and elegant posture.
We can't have all the information in the background Java, which makes the server very tired, and very troublesome. Moreover, we need some cool design, want to through the direct operation of HTML can be achieved, for example, verify the input number format is not correct, for example, at some appropriate time to pop up a prompt box, such as I want HTML at my mercy, before passing to the background of Java I have to do these, Bing, grain first, javascript is for you, it is a programming language invented to make it easier to manipulate HTML. We can define some objects to better encapsulate the request, you can define some methods to manipulate the various parts of the HTML, you can write an event, trigger when the mouse clicks on a button, and so on. and dom (Document Object model) is to assist JavaScript in this mission, which encapsulates all elements of HTML into objects, Manipulate these objects through JavaScript. Moreover, Dom also depicts HTML elements as a tree structure, each element corresponding to each node and location, it is more convenient for us to the HTML to be added and checked. Unlike Dom,javascript, which uses bom (Browser object model) to encapsulate information about the browser as an object to facilitate the operation of the browser (if a page is returned , forward one page, history, etc.). Dom just manipulate the underlying structure of the HTML, and sometimes it is not enough, such as when I click on a button, I want to pop up a prompt box while the button to color, that is, I want to give the button to bind two events, then use the DOM2. DOM2,DOM3 extends the DOM, allowing JavaScript to have better interactivity with HTML. Many times, we submit too much request information, backstage in the processing of this information will appear in a hurry, and json came into being, It encapsulates a series of request information into a regular string, convenient for the client to send, also convenient server-side processing, no rules inadequate surrounding area, JSON is the rule.
JavaScript has been so handy to manipulate HTML, but it still looks awkward, and even if you use it to take out a small HTML button, you need to enter a very long code (GetElementsById ... , so there's JQuery, which is based on the JavaScript framework, and it can use very little code to achieve the same effect as pure JavaScript, with four or two dials, but it's essentially JavaScript. And because of historical reasons, many of the Internet Explorer rules and other new sharp browser are different, resulting in JavaScript often want to write different code for IE and other browsers, such as adding event function to the button to use different methods, but jquery unified this problem, swept the Liuhe, Let IE and other browsers have the same treatment.
As we have said before, the front-end HTML request information sent to the background servlet,servlet output to the front end, then if the results to be output contains a lot of static HTML code needs to return, then a line of HTML to be in this background Java code piece, and finally back to the front end, HTML and Java code into a lump, it is really unsightly. The advent of JSP makes the whole world fresh. The JSP softens the HTML and servlet, which is essentially a perverted servlet that, when the server compiles, translates the JSP into a servlet and then follows the servlet's processing. JSP embeds HTML and servlet, has its own format, has its own instructions, has its own object, has its own set of rules, but its smiles, in its transformation of the servlet file, can find the corresponding shadow. It let the background Java only deal with the logic of the processing, and the cumbersome HTML stitching, instructions and a lot of scissors constantly messy code soft synthesis, ice wheel off the island, the universe is exceptionally clear.
Again, even with the JSP, the native servlet still has to deal with a lot of logic, if the logic is very much, every time the servlet busy busy, but also processing the request parameters, but also take the parameters to the database query results, but also gu this, is Guna, overwhelmed. When the system is huge, the Java code becomes a new lump. MVC(model,view,controller) solves this problem by straightening out models (such as transcript objects), presentation layers (such as JSP pages), control layers (logic to process), Ding, there, three pillars, and common governance. And the Struts2 and Spring Framework is the typical MVC pattern, and on this basis to publicize the personality. (for example, STRUTS2 will intercept each request message and do some processing before handing it over to the servlet.) And spring features more chic, there are a lot of code that should be implemented in Java, through the XML configuration can be done, even if you do not know the programming language can participate in it, really is all ages, popular tastes.
From CSS to the servlet to JSP, STRUTS2, steamed javaweb the back and forth.