Tomcat installation configuration and Javaweb Getting Started tutorial

Source: Internet
Author: User
Tags tomcat server

The development environment of this article:

Windos7, Eclipse-mars, JDK1.7, Tomcat7.0

This article was originally a group of internal information, but in the spirit of sharing, also sent out, I believe, this should be a more detailed article.

1. About Tomcat

First look at the introduction of Tomcat:

Tomcat is a core project of the Apache Software Foundation (Apache Software Foundation) Jakarta Project, developed by Apache, Sun, and other companies and individuals. With Sun's involvement and support, the latest servlet and JSP specifications are always reflected in Tomcat, and Tomcat 5 supports the latest servlet 2.4 and JSP 2.0 specifications. Because of the advanced Tomcat technology, stable performance, and free, so deeply loved by Java enthusiasts and have been recognized by some software developers, become the most popular Web application server.

Tomcat server is a free open source Web application server, belongs to the lightweight application server, in small and medium-sized systems and concurrent access users are not widely used, is the first choice to develop and debug JSP programs. For a beginner, it can be thought that when the Apache server is configured on a single machine, it can respond to requests for access to the HTML (one application under the standard Universal Markup Language) page. The tomcat part is actually an extension of the Apache server, but it runs independently, so when you run Tomcat, it actually runs separately as a separate process from Apache.

The trick is that when configured correctly, Apache serves HTML pages, while Tomcat actually runs JSP pages and Servlets. In addition, like a Web server such as IIS, Tomcat has the ability to handle HTML pages, and it is also a servlet and JSP container, and the standalone servlet container is the default mode for Tomcat. However, Tomcat is less capable of handling static HTML than the Apache server. Currently, the latest version of Tomcat is 9.0.

Say so much, next i from the actual application and development point of view of Tomcat, first of all, you have to know, it is an open source project, since open source, we downloaded a tomcat online, is free to use. OK, this is not a problem, in our actual development process, the general is to use Tomcat for project testing. To put it simply, when I write a Web project, just write it, deploy it to Tomcat, then look at the effect, if it doesn't feel right, change it, then restart Tomcat, and then look. In most cases, as a javaweb developer, you will have to deal with this three-legged cat almost every day.

In this section, I'll teach you how to use Tomcat.

2. How to install Tomcat

First, go to the group file download Tomcat7.0 (or Baidu), put it under the Software folder.

Unzip, this will certainly.

8088 indicates that the port number of this tomcat is 8088, we will use the default port 80, do not use 8088, if the port is 80, the address bar in the browser can be omitted to write. Here, let's delete [8088] in the folder name. Now let's take a look at the directory structure:

At present we only care about bin and conf these two directories, let us first open the Conf directory, inside are some configuration files, find Server.xml, other no tube.

Right-click Edit and open it with Notepad.

Since Notepad has no code highlighting, many places are inconvenient, let's open eclipse and change it in Eclipse. Save it first, and then open Eclipse. Oh, yes, there is a plug-in, well, before you open eclipse, go to the group file to download a jar package. (Or you Baidu, find this jar package and download it.) Of course, if you use myeclipse it doesn't matter, because it comes with this function. I also forget where to download from, in short, Baidu Bar itself ~ Actually I do not like myeclipse,eclipse much good ah, free and lightweight. )

Download this thing and open the Eclipse installation directory and open the plugins

Then, start eclipse, and you'll see a small briefcase icon in the main interface.

Its role is to open the file directory, I will show you later.

2. Start writing the first Javaweb project

Now, let's build a Web project with Eclipse. In Project Explorer, right-click

New--Dynamic Web Project

The project name is called HelloWorld, then click Next

Continue to click Next

Finally, click Finish, this is our first Web project.

We right-click on the WebContent directory, new a JSP File

File name is index.jsp, click Finish directly

Ouch, error, we don't care about this mistake for the time being. Now, let's change the code. We just created the JSP page, the default encoding is iso-8859-1, this code is not allowed us to enter Chinese. If you don't believe it, you can write a few words of Chinese in it, it can't be saved. We now change all iso-8859-1 of JSP page to UTF-8

Like me, check iso-8859-1, then, CTRL + F, jump out of this thing

In the second box, write the UTF-8, which is an international code that supports all languages, including Chinese.

Click Replace All to replace all.

It's all over, okay. Every time this change is not very troublesome Ah, there is a better way, please refer to this article:

Address: http://www.xiaotublog.com/blog/articles/85.html

Please follow the method described in this article, the workspace and JSP page default encoding is set to UTF-8, do not use GBK, all with UTF-8, good.

Now, we right-click on the project to choose Properties, the code of this project is also changed to UTF-8

Did you fix it? OK, so we go on, did not have an error question? Now let's get rid of this error, OK, first, open the Tomcat installation directory.

Is there a Lib directory inside, open

Find Servlet-api, copy. CTRL + C, I say it again, CTRL + C. Then, back to our project, in this place Ctrl + V

Paste it over, instant no error.

You don't care why, just follow me one step at a. Now, I'm going to post this project to Tomcat, and here I offer a very flexible way, and I know that many of you already have the basics, and you know that in MyEclipse, you can deploy Web projects directly. However, I do not recommend that way, today, I teach you a better way, do not use that old-fashioned way, I know, some of you do not want to put this project, to Tomcat inside the WebApp folder lost Ah, I suggest you do not use this way, not very good. OK, now, everyone follow me step-by-step. Mouse click on the item like this:

Have a selected effect, then, click the icon for that briefcase.

Click here and the real catalogue of the project will come out.

My path is: E:\Java training \software\eclipse-mars\workspace\helloworld

Open this folder:

To copy this path, my path is: E:\Java training \software\eclipse-mars\workspace\helloworld\webcontent

OK, next, go back to the Tomcat installation directory and quickly find the server.xml we modified earlier, and drag it into eclipse:

Switch to Source view

Now, I'm going to teach you how to match up the project, okay. Write this configuration item on:

Docbase represents the release directory of our project, that is, just E:\Java training \software\eclipse-mars\workspace\helloworld\webcontent, note oh, it must be published in the directory, in this project, Is WebContent, which is this:

Path is a route map (I prefer to use this noun to illustrate the meaning of path), that is to say, we access the project through a browser, the name of the access is the value of path, even if your project is called AAA,BBB,CCC, it doesn't matter, what path is, we use what to access. Let's configure the route map to/haha.

The remaining two items are used by default, not configured. In the end, I configured it like this:

There is another place, is to configure this Tomcat port number, we changed to 80 port, the original is 8088

CTRL + S save. Let's go back to the Tomcat installation directory, open the Bin folder, find a file called Startup.bat, and double-click to open it.

This means start complete, then open the browser, enter in the Address bar: localhost/haha/, carriage return

Nothing, because our index.jsp does not have much content, now, we write a sentence:

Save, and then go to refresh the browser.

Come on, clap!

Finally, we're going to configure Tomcat inside Eclipse, because this heibuliuqiu window doesn't look good and it's not easy for us to debug.

The idea is that in eclipse, Window--Preferences

Click Add to load the Tomcat installation directory in.

Read it, then click on the right side of this:

This is what we saw in the black window just now.

Note that if you do this, eclipse will have a virtual tomcat, so we need to copy the configuration just now, and change it here:

Change it in the Server.xml:

Reboot the Tomcat server and it will be OK.

Tomcat installation configuration and Javaweb Getting Started tutorial

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.