Understanding of the execution process of Web projects, starting with an HTTP request such as Http://localhost:8080/test/login.action

Source: Internet
Author: User
Tags http request xmlns tomcat

Understanding of the Web project execution process, including 1 HTTP URL 2 html, servlet, JSP 3 Tomcat and so on. The entire execution of the Web project, starting with an HTTP request such as Http://localhost:8080/test/login.action:

1 There are three main forms of HTTP URLs:

1.1http://localhost:8080/test/index.html, or static page

1.2http://localhost:8080/test/index (the passed-in parameter can be attached later), where/index is mapped to a servlet class,

The whole needs to be configured in the test project's Web. XML:

<?xml version= "1.0" encoding= "Iso-8859-1"?>
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
version= "3.0"
Metadata-complete= "true" >
<servlet>
<servlet-name>index</servlet-name>
<servlet-class>IndexSerlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
</web-app>

The execution process is:

1) Enter Http://localhost:8080/test/index in the browser

2) Tomcat get Http://localhost:8080/test/index

3) Indexservlet.class file of the test project under the WebApp folder of the Tomcat under the <servlet-mapping> location in Web. xml

4) Execute the Indexservlet.class file and return the HTML code

5) Tomcat is responsible for interacting with the browser and displaying the HTML code in the browse

1.3http://localhost:8080/test/index.jsp (can be attached with incoming parameters later)

This way of accessing is actually the servlet mode in 1.2.

Execution process:

1) Enter http://localhost:8080/test/index.jsp in the browser

2) Tomcat get http://localhost:8080/test/index.jsp

3) Call Tomcat's work directory under the test project index.jsp corresponding servlet.class files such as Index_jsp.class (the process from JSP to servlet class is Tomcat auto-converted)

4) Execute the Index_jsp.class file and return the HTML code

5) Tomcat is responsible for interacting with the browser and displaying the HTML code in the browse

To display

1.4http://localhost:8080/test/index.action (can be attached with incoming parameters later)

This approach is typically achieved using a framework such as struts.

Execution process:

1) Enter http://localhost:8080/test/index.action in the browser

2) Tomcat get http://localhost:8080/test/index.action

3) According to the Struts mapping configuration in Web. XML, locate the corresponding class file in the test project under Tomcat's WebApp folder, such as the Index.class file

4) Executes the Index.class file, and the struts framework renders the specified JSP page in a browser display:

For example, the Struts framework generates HTML code by setting which JSP page to parse in the Struts.xml configuration file:

<action name= "Login" class= "Buct.scanner.action.LoginAction" >
<result name= "Success" >/login.jsp</result>
<result name= "Input" >/index.jsp</result>
</action>

5) Tomcat is responsible for interacting with the browser and displaying the HTML code in the browse

The entire rendering process is done by the struts framework (that is, during the run of the program, the Struts.xml configuration file is parsed as needed during the class run in the Class,jar package in the jar package called struts), rather than Tomcat.


========= comprehensive analysis of the evolution process of several ways ========

The Order of development is:

1http://localhost:8080/test/index.html

2http://localhost:8080/test/index

3http://localhost:8080/test/index.jsp

4http://localhost:8080/test/index.action

Here's why it's going to evolve so that it solves some of the drawbacks or problems of the previous approach.

1) http://localhost:8080/test/index.html is static page mode, can only load static pages, if I create a new user, to do saveadd operation, this way is not possible.

2) So with the http://localhost:8080/test/index that is the servlet way, this way can be done through the Servlet.class file background database operations, and splicing HTML code in the browser to display.

3) Since the Http://localhost:8080/test/index is the servlet this way, why Sun company also invented JSP. Although the servlet can implement database operations, but to splice HTML, this way is not intuitive and not image, so invented the JSP. In the JSP can write Java code to access the database, but also can visually see the HTML code, such as this example http://zhidao.baidu.com/link?url= Nrae1vpntz1ikktyiyqo0iqahx71ifodc0yno89zhfryjdiotc9l-qoshtehhawgb9canfagugoezypwu64yfq.

4) Since there is JSP this way, why also http://localhost:8080/test/index.action this use of struts and other frameworks. Because JSP can write Java code to access the database, but also can visually see the HTML, but the HTML code and Java code mixed together, not conducive to the readability of the program, code writing is still more confusing. So there is a struts, SPRINGMVC, struts, and so on, to achieve the separation of Java code and HTML code is to distinguish between the front and back end, Java code in the back-end writing, HTML code in the JSP writing and with the parameter transfer mechanism.

In fact, http://localhost:8080/test/index.action way and struts and other framework, is the http://localhost:8080/test/ Index is the way the servlet is upgraded: The ①servlet method returns the HTML code (which is what the programmer did), then Tomcat accepts the HTML code and interacts with the browser, Display ②struts in the browser by parsing the specified JSP code in a class and returning the HTML code (these are struts, the programmer does not need to do it, Programmers only need to specify the JSP that the class wants to display in Struts.xml and write the JSP interface, and Tomcat accepts the HTML code and interacts with the browser.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.