Build a Web server on MyEclipse

Source: Internet
Author: User

A) What is a servlet?

Servlet (server-side applet) is a server-side program written in the Java language [O1], which can be used to generate dynamic Web pages using scripting languages.

b) The schema of the servlet?

    1. Also the server schema is sprinkled.
    2. The location of the servlet in the WEB application

c) The task of the servlet?

    1. Read client (browser) data:
      1. an explicit [O2] Httl request data (HTML form on a Web page, or it can be a form from an applet or a custom HTTP client program)
      2. . implicit [O3] HTTP request data (cookies, media types, compression formats that the browser can understand, and so on)
    2. Process data and generate results
    3. Send data (that is, documents) to the client (browser)

d) MyEclipse tool operation Servlet

1. Create a Web server project,

2. Create a new package,

3. Create a new servlet file,

4. Change the path in Web. XML "This is very important!" "

5.run as (My Eclipse application)"NOTE: see if the project is deployed HA"

6. Look at the port number:

Info: Starting Coyote http/1.1 on http-8080

7. Access in the browser: 192.168.2.19 is host

Http://192.168.2.19:8080/MyWebSeverProject/MyServlet

What is printed in the browser: This is class Cn.com.fs.test01.MyServlet, using the GET method

"Note: The servlet file has not been changed again and requires a reboot"

8. Note Several statements in the servlet:

(1) public void doget (HttpServletRequest request, httpservletresponse response)

Throws Servletexception, IOException {

Parameters: Request: Contains client requests information response set the information returned by the service side

(2) Response.setcontenttype ("text/html");//Set the format of the returned content

(3) PrintWriter out = Response.getwriter (); The Printin method of the PrintWriter object can be interpreted as directly returning data

(4) Out.flush ();//Refresh--Transfer data all the time

(5) Out.close ();//close--data transfer complete, end

[O1]

    1. Vip
    2. Web Development

[O2] Look at the code to understand

[O3] such as compression format Zip,rar

Build a Web server on MyEclipse

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.