Introduction to JSP and servlet description

Source: Internet
Author: User

What are Servlets and JSPs

There are two main techniques for developing Web applications in Java, namely Servlets and JSPs. A servlet is a Java program executed on the server side, and a program called a servlet container (which is actually a server) is responsible for executing Java programs. The JSP (Java Server page) is a page that is executed by the JSP container .

The most important difference between servlet and JSP is that the servlet is dominated by Java programs, the output of HTML code needs to use the OUT.PRINTLN function, that is, in Java embedded HTML, and JSP is based on HTML pages, When you need to write Java code, you insert Java code directly into the page, which is embedded in the HTML. A typical example is as follows:

JSP file

Copy CodeThe code is as follows:
<body>
<% out.println ("JSP"); %>
</body>


Servlet

Copy CodeThe code is as follows:
public class Myservlet ... {
...
Out.println ("Out.println ("<body>");
Out.println ("
Out.println ("Servlet");

Out.println ("Out.println ("</body>");
Out.println ("}

It can be seen that the JSP is easy to output, while the servlet facilitates logical processing. Therefore, the practical application of the two are often used in combination, their respective roles.

And Tomcat is the servlet container and the JSP container mentioned above. The following scenarios support the SERVLET/JSP protocol for each version:

Tomcat version Support Servlet Support JSP
6.0.x 2.5 2.1
5.5.x 2.4 2.0
4.1.x 2.3 1.2
3.3.x 2.2 1.1

Structure of the Web application

After Tomcat is installed, you can look at the WebApps directory under the Tomcat directory. This directory is used to save the Web application.

The root directory is the directory that should be placed in the WebApps directory. The Web-inf directory cannot be accessed from the browser. Web-inf/classes is a compiled Java program (primarily a servlet), and Web-inf/lib is the repository file (. jar file) used by the runtime, and Web. XML is the configuration information for the entire application.

Other files, such as. JSP, pictures, JavaScript scripts, and so on, can be placed directly under the Web application's root directory.

MVC model

The so-called MVC model is a method of separating data, logic processing and user interface.

    • M (model, models): For data processing, logic processing.
    • V (view): Used to display the user interface.
    • C (Controller, controllers): Control the logical direction and screen according to the client's request.

In Java, the three parts of MVC correspond to JavaBeans, JSP, and servlet, respectively.

    • M = JavaBeans: Used to pass data, with data-related logic processing.
    • V = JSP: Receive data from model and generate HTML
    • C = Servlet: Receive HTTP requests and control model and view

The picture is as follows:

Introduction to JSP and servlet description

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.