jsp and servlet and struts2

                                      jsp and servlet and struts2

jsp depends on the servlet

jsp: a dynamic web technology, the full name of JavaServer Pages, is a dynamic web technology standards led by Sun Microsystems created. JSP deployed on a network server, can respond to a request sent by the client, and generates the Web page HTML, XML or other format documents dynamically according to the request, and then returned to the requestor. Because it runs on the server side, so it is the server language. Act as part of the view in mvc.

For example: When a client makes a request to http; // ...... when index.jsp, 1 server will find the corresponding server-side jsp file, it first translated into two java files, and then compiled into byte. code, 3. then execute the file, the results of execution (generated html file) page returned to the client display. Note: 1,2,3, it is executed on the server side.

Jsp files in response to the dynamic page is requested java script file is embedded in the html.

Later, people think the business logic code and Bean show mode code and view together, too complicated and inconvenient. So created model1, and later created the MVC pattern, MVC mode put things performed by the server is divided into three parts. View of a portion, the bean portion model and logic control section (primarily processed data to generate new data.) By the interaction between the three them to generate a final result, to respond to the client's request.

Here I had a question, we usually comes to the front, how divided the background? Because now the view is in the background, the front end portion of the view here is, what is the difference? Its front end is it refers to jsp file server? Or is that the result finally generated.

servlet: Java Servlet running on a web server with support for Java Servlet specification interpreter of the Java class. Refers to the server, as long as the server has the Java Servlet specification interpreter, the java code exists on the server side can be called servlet.

servlet tasks:

  • Read client (browser) of the transmitted data explicit. Form HTTP client program that includes HTML form on a web page, or may be derived from or customized applet.
  • Read client (browser) sends implicit HTTP request data. This includes cookies, media types and browsers can understand compression format, and so on.
  • Processing the data and generate a result. This process may need to access the database, the implementation of RMI or CORBA calls, call the Web service, or directly calculated corresponding response.
  • Transmitting the explicit data (i.e., document) to the client (browser). The format of the document can be varied, including text files (HTML or XML), binary files (GIF image), Excel and so on.
  • Sending an implicit HTTP response to the client (browser). This includes tells the browser or other client is returned the document type (eg HTML), set cookies and cache parameters, and other similar tasks. 

jsp (not simply the only server-side jsp files) representing an increase over the course of a servlet (jsp files into a servlet to process) so we say jsp dependent on the servlet.

struts2: a MVC development framework, to simplify the code redundancy and complexity of site development. It is only a framework. It does not change the composition of the site. It is simply encapsulates some redundant code in MVC. Its essence is still a client makes a request, the server receives, submitted to the appropriate components, and data processing, generate the final answer to the html file requested by the client. When only struts2 server receives a request, sent to the core of the filter), and then to match the corresponding file struts.xml actin, after performing the action returns the return value (a string) and then find the matching profile struts.xml corresponding match page.

struts2 does not depend on servlet. It enables the decoupling of the servlet. But we can still call the servlet in struts2. struts2 provides its own methods to achieve servlet functionality, it is precisely because this feature was able to achieve a decoupling of the servlet.

 

 

发布了14 篇原创文章 · 获赞 8 · 访问量 4736

Guess you like

Origin blog.csdn.net/qq_41223538/article/details/104033372
Recommended