Servlet Usage Analysis for JSP learning and jspservlet usage

Source: Internet
Author: User

Servlet Usage Analysis for JSP learning and jspservlet usage

This article describes the Servlet usage of JSP learning. Share it with you for your reference. The specific analysis is as follows:

Servlet is a Java program written using the assumervlet application design interface. It is derived from the request/response mode and can accept Http requests from the client browser to generate a response and return the client.

Differences and connections between Applet JSP JavaBean and Servlet

Both the Applet and Servlet do not have the main () method. Only some specific methods are used to start execution and exit. However, the Servlet does not provide the user interface and runs on the server, while the Applet provides the user interface, run on the client.
Servlet and JavaBean are both written in Java, but JavaBean cannot run independently. It only provides interfaces for JSP access, while Servlet can run independently.

Before the emergence of JSP, Sun introduced Servlet. However, when using Servlet to write HTML scripts, the print or println method is required to print the output one by one, which brings a lot of trouble to the development; JSP web pages embed Java code in HTML scripts, which fundamentally changes the programming method.

JSP an can communicate with Servlet. For example, JSP can call JavaBean or Servlet. After the Servlet processes data, it can be displayed on the JSP page.
All servlets directly or indirectly implement the javax. Servlet. servlet interface.

Servlet lifecycle:

When the init () method is called
Run, when the service () method is called
End: When the destroy () method is called

How to compile web. xml:

The first line <? Xml version = "1.0" encoding = "ISO-8859-1"?> Describe the xml version and Character Set
The second line is <web-app>... </web-app>, which is the main information of xml.

Name the Servlet in xml and customize the URL

<Web-app xmlns = "" xmlns: xsi = "" xsi: schemaLocation = "" version = "2.4"> <display-name> Servlet technology </display-name> <description> Servlet instance </description> <servlet-name> SampleServlet1 </servlet-name> <servlet-class> ch7.SampleServlet1 </servlet-class> </servlet> <servlet-mappint> <servlet-name> SampleServlet1 </servlet-name> <url-pattern>/ch7/SampleServlet1 </url-pattern> </servlet-mappint> </web-app>

Enter http: // localhost: 8080/myapp/SampleServlet1 in the browser.
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: 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.