HelloWorld program example for getting started with JSP

This example describes the HelloWorld program for getting started with JSP. Share with you for your reference, as follows:

Here's the first JSP -- HelloWorld! Every "first love" brings a sense of mystery and unveils the mystery of JSP!

JSP is also a specification of J2EE.

JSP (Java service page) is a dynamic web page technical standard advocated by Sun company and established with the participation of many companies.

The difference between JSP and html is that Java code and JSP tags are embedded in web pages to form JSP file.

The web application developed by JSP is cross platform, which can run not only under Linux, but also on other operating systems.

It is said that the reason why we just learned servlet and later learned JSP is that when we use servlet, too many HTML codes are too cumbersome when returning the page to the client, and if we change the servlet code, we have to recompile it once, restart Tomcat and resend it to the client. Moreover, it is not very convenient if we beautify the return page, So the sun company considered the programmer thoroughly.

So JSP came into being.

What about the mechanism of JSP? Let's write a HelloWorld JSP file and start the Tomcat server to run successfully, but how is this process realized? What is the relationship between JSP and servlet? What is the relationship between JSP and ASP? Let's discuss it next.

first. JSP file:

How is JSP page implemented? Mechanism?

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

Describe the operation process in detail:

1. First, the web client sends a URL request to Tomcat. The server obtains the request and analyzes the request string if the suffix is JSP file, Tomcat will call JspServlet for processing. JspServlet is 2 If the JSP file is called for the first time, the JSP will be compiled into a servlet. If the JSP is not called for the first time, it will not be compiled. The JSP file will only be compiled once without modification. 3. Tomcat calls the service () method to compile the JSP file and create a. Java and. Class file. The java file inherits from the parent httpjspbase class.

4. Create HttpServletRequest class and httpservletresponse class 5 Call Java inherits the httpjspbase class method service (request, response) of the parent class. 6. Call the jspservice (request, response) method in the service method to render HTML and return it to the client.

What is the relationship between JSP and servlet?

First contact with JSP and servlet, as mentioned earlier, JSP appears after servlet. The operating mechanism of JSP is also better understood. In fact, JSP is a servlet, but Tomcat does some repetitive things. JSP makes up for the shortcomings of servlet and is more humanized.

Differences:

Servlet is completely composed of Java code and is good at process control and transaction processing. JSP is composed of HTML code and JSP tags, which can easily write dynamic web pages. Therefore, in practice, servlets are used to control business processes, while JSP is used to generate dynamic web pages. JSP is equivalent to an extension of Java and HTML that can be combined together JSP file. JSP focuses on views, and sevlets are mainly used for control logic.

I hope this article will help you in JSP programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>