The first step to opening a new World: learning the servlet

Source: Internet
Author: User

    • What is a servlet?

is a server-side program written in Java. Its main function is to interactively browse and modify data to generate dynamic Web content.

    • Create a servlet

First, create a Web project

1) Process: Eclipse-file-new-other-web-denamic Web Project-next (refer to drawings)

2) Enter the project name, Target Runtime, configuration, and click Next when you are finished. If you do not have an integrated tomcat, configure it first.

3) This page does not need to modify and fill in the content, directly click Next, go to the next page

4) Check the selection in the drawings, click Finish, complete the creation

Second, modify the view and create the servlet

1) For example, the Web project is displayed as follows:

2) Click Windows-show view-other-java-package Explorer in the navigation bar, click the 0k button

3) View the project directory at this time as follows:

4) Create a package under the SRC file

Process: Right-click src-new-other-java-package-next-to fill in the Package name-click the Finish button, as

5) Create servlet

Process: Select New Package Right click-new-servlet-Fill in Class Name-next-next-finish (where Doget () and Dopost () method are checked)

    • Compiling and requesting

Open a new servlet

Add the code in the Doget () and Dopost () methods, import the Printwrite package,

Configure Tomcat, click servlet-Double-click tomcat-Select modules-click Add Web modoules-Double-click the new servlet, click the OK button

Running a servlet

Right-click Tomcat-debug

Enter in the browser: Http://localhost:8080/JAVAWeb_Servlet_Study_001/ServletDemo_001,enter run

Note:

LocalHost is the domain name, which is your server address, now you are running on this machine, localhost is the representative of your local machine, you can also use 127.0.0.1 instead
Or you can open the command operator interface (remember that this does not, as the view JDK version open that interface, and then enter Ipconfig return to see their own IP address), with this IP address replacement is also possible.
8080 is the port number of the Tomcat service (each service on the Windows operating system will have a corresponding port number)
JAVAWEB_SERVLET_STUDY_001 is the context.
ServletDemo1 is the name of the annotation above the class you created.
Also, modifying these configurations requires a reboot to take effect

The first step to opening a new World: learning the servlet

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.