Java Learning 2: Developing a simple Web Application__java based on IntelliJ idea

Source: Internet
Author: User
Tags tomcat server

The previous article describes the configuration of the development environment and the installation of the IDE, and this article describes how to develop a simple webapp from scratch.

Note: All the steps have screenshots, and has been marked red in the screenshot, you can also directly follow the screenshot to operate.


First, create a Web project

(1) Open IntelliJ idea and click "Create New Project":

(2) First select "Java" on the left menu, then click "New ...";


(3) then select your JDK installation directory in the window, click "OK", then tick "Web application" under "Java EE" and click "Next" at the end;

(4) Enter your project name in Project name, enter the path of the project in "Project Location", or click a button with an ellipsis later to select a folder.

Note: IntelliJ idea does not automatically create a folder with the same name in the selected folder, but instead directly stores the project file in the directory of your choice, so if you have not previously created a folder with the same name as your project, you can location in project Enter the path as in the Mark section of the screenshot. Then, clicking Finish will pop up a conversation box asking if you want to help you create a "Test" folder in the "Java" folder, and we'll click "OK", as shown below:

(5) After the new project is built, we need to create two folders: Classes and Lib

Two functions of a folder:

classes--Store the compiled Java class file;

lib--Store the referenced jar package.

We created two folders in the Test/web/web-inf directory (pictured below). Right-click on the Web-inf to select:-> "New"-> "Directory", and then enter the folder name in the dialog box;



(6) Now, we need to configure the two folders that were created in the previous step in the project

1. Configure classes

Right-click on the project root directory "Test" and select "Open Module Settings" in the menu;

In the pop-up window, check "Use module compile OUTPU path" and click the ellipsis button after "Output path" and "Test Output path" to select the "Classes" folder located under "Web-inf". Finally click "Apply" (pictured below);

Note: It is under the "Paths" column of "Modules"

2. Configure Lib

Select "Modules" in the "Dependencies" column, click on the right "+" button, in the menu select "JARs or directories ...";

Then, select the "Lib" folder under "Web-inf" and click "OK".

Then, select "Jar Directory" in the window and click "OK".

Finally, we will see that "Lib" has been added successfully, we can directly hit the "OK" button, or first click "Apply" and then click "OK". (pictured below),


Second, configure Tomcat

(1) First click on the project main interface to the upper right side of the gray button with the inverted triangle, and then click "Eidt configurations ..." (pictured below);


(2) Then, click the "+" button in the top left corner of the pop-up window and select:-> "Tomcat Server"-> "local" in the menu.

(3) Then, enter the name in "Name" and click "Configure ...";


(4) then click the "+" button in the top left corner of the window and the button on the right of the new window clock with an ellipsis, select your Tomcat save path, click "OK";

(5) Next, Cancel tick "after Lauch", click "Apply". At this point, there will be a warning: warning:no artifacts marked for deployment, next, we configure the artifacts;

(6) Click "Deployment", click "+" button, select "Artifact ..." in the menu.

(7) Enter any letter in the "application context", such as:/webapp. You may ask application what the context is. For example, a URL www.xxx.com/webapp,Application context is the "/web" of the site clock, and so we will use.


Third, Web Access

(1) in the project "\test\web" directory, open "index.jsp", in the <title></title> label to enter the title of the page, in the <body></body> tab to enter the content of the page, Then, click on the Green Triangle button in the upper right corner to run the local server.

(2) In the browser address bar type "Http://localhost:8080/web", press "enter" see, you will see the following page:


Now, you are not especially excited. Don't be busy, the Java pit is still deep, let's take a look at the next 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.