JSP Primer HelloWorld Program Instance _jsp programming

Source: Internet
Author: User
Tags tomcat server

The example of this article tells the HelloWorld program of JSP Getting started. Share to everyone for your reference, specific as follows:

This tells the first jsp-helloworld! Each time the "first Love" with a mysterious sense, uncover the veil of the mysterious JSP!

JSP is also a specification of Java EE.

JSP (Java Service page) is a Dynamic Web page technology standard that is initiated by Sun company and is built by many companies.

The difference between JSP and HTML is to embed Java code and JSP tags in a Web page to form a. jsp file.

JSP developed Web applications that are Cross-platform, run on Linux, and run on other operating systems.

Just learned the servlet, after the JSP, it is said to be because we use the servlet, when the return page to the client too much HTML code too cumbersome, and a little changed the servlet code to recompile the restart Tomcat again sent to the client more cumbersome, And if we do some landscaping on the return page is not very convenient, so someone else sun company for programmers to consider well.

So JSP emerged.

What about the JSP's operating mechanism? We write a helloworld.jsp file, start the Tomcat server and run successfully, but how is this process implemented? What is the JSP related to the servlet? What is the relationship between JSP and ASP? Below we Yi Yilai to discuss.

First. jsp file:

 
 

How is JSP page implemented? Mechanism?

In fact, when you request a JSP page through HTTP, first Tomcat will speak JSP compiled into a servlet and then execute the servlet.

In detail, this is the running process:

1. First, the Web client sends a URL request to Tomcat. The server obtains the request, analyzes the request string, and if the suffix name is a. jsp file, Tomcat invokes the Jspservlet processing. Jspservlet is
2. If the JSP file is invoked for the first time, the JSP will be compiled into a servlet and will not be compiled if the JSP is not the first call. The JSP file is compiled only once without modification.
3. Tomcat invokes the service () method to compile the JSP file and create a. java and. class file. The Java file inherits from the parent class Httpjspbase class.

4. Create HttpServletRequest class and HttpServletResponse class
5. Invoke. Java inherited parent class Httpjspbase class method Service (Request,response)
6. Call the Jspservice (Request,reponse) method inside the service method and render the HTML back to the client.

JSP and servlet relationships?

First contact with the JSP and Servlet, previously said, JSP is the post servlet appears. JSP operating mechanism is also more understanding, in fact, JSP is a servlet, but some duplication of things let Tomcat to do. JSP makes up for the shortcomings of the servlet, more humane.

The difference:

Servlet is a complete Java code structure, good at process Control and transaction processing
JSP is composed of HTML code and JSP tag, it can easily write dynamic Web pages.
In practice, the servlet is used to control the business process, and JSP is used to generate dynamic Web pages.
JSP is equivalent to a file in which Java and HTML can be grouped together with a. jsp extension.
JSP side attention to the graph, Sevlet mainly used for control logic.

I hope this article will help you with JSP program design.

Related Article

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.