The servlet usage analysis of JSP learning _jsp programming

Source: Internet
Author: User

This article describes the servlet usage of JSP learning. Share to everyone for your reference. The specific analysis is as follows:

A servlet is a Java program written using the Javaservlet application design interface, originating from the request/response pattern, accepting HTTP requests from the client browser, generating a response, and returning the client.

Differences and relationships between Applet JSP JavaBean and servlet

There are no main () methods in the applet or servlet, only some specific methods for starting execution and exit, but the servlet does not provide a user interface to run on the server side, and the applet provides the user interface to run on the client.
Both the servlet and the JavaBean are written in Java, but the JavaBean cannot run independently, providing only the interface for JSP access, while the servlet can run independently.

Before JSP, Sun introduced the servlet, but because of the use of the servlet to write HTML scripts, you need to use the print or Println method to step through the output, the development of a lot of trouble; JSP Web pages are embedded in the HTML script Java code, fundamentally changing the way the programming

JSP JavaBean and servlet can communicate, for example: JSP can invoke JavaBean, or you can call the servlet, after the servlet processing data, can be displayed through the JSP page.
All servlet implementations Javax.servlet.Servlet interface directly or indirectly

The life cycle of the servlet:

When a call to the Init () method is initialized
execution, when the service () method is invoked
End, when the Destroy () method is invoked

How to write Web.xml:

The first line <?xml version= "1.0" encoding= "Iso-8859-1"?> describes the version and character set of the XML
Second line <web-app>..............</web-app> This is the main message of XML

Name the servlet and customize the URL in XML

<web-app xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
 xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemalocation= "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version= "2.4" >
< Display-name>servlet technology </display-name>
<description>
 servlet instance
</description>
<servlet>
 <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>

Then enter in the browser: Http://localhost:8080/myapp/SampleServlet1

I hope this article will help you with the 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.