New Web project in Eclips

Source: Internet
Author: User

1. Download eclipse from www.eclipse.org, it is highly recommended to download the Eclipse IDE for Java EE developers version, this article is based on Eclipse 4.2.1 (Eclipse Juno SR1).

2. after the download is complete, unzip to local, this article assumes (d:\), switch to D:\eclipse, double-click eclipse.exe, start Eclipse.

3. The first time you start Eclipse , you will be asked to specify the workspace path,Workspace is primarily used to store the settings of some eclipse tools themselves, It can also be stored in projects developed by Eclipse. This article assumes "D:\workspace", and you can tick "use this as the default and does not ask again"so that every time you start Eclipse This dialog box is required. You can cancel this option again from window>prefrences if you need to do so later .

4. usually after reinstalling Eclipse , the first thing I do is to customize the IDE 's interface. Specifically, I set the following key:

4.1 into window>show view>other ... , in the dialog box that pops up, open your favorite view panel, such as Package Explorer, JUnit, and more.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://a.hiphotos.baidu.com/album/pic/ Item/d52a2834349b033bc308743915ce36d3d439bd55.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "415" width= "758"/>

4.2 into window>customize perspective, in the popup dialog box,the tool bar Visibility tab corresponds to the toolbar, where you can remove your unwanted icons , plus their usual;shortcuts the menu item that corresponds primarily to the new action in the right-click menu in the Package explorer and Project Explorer views , you should also remove the unwanted ones and add the usual ones.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://f.hiphotos.baidu.com/album/pic/ Item/aec379310a55b319d6e6099643a98226cffc1731.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "558" width= "758"/>

4.3 Click window>preferences, pop up the Preferences dialog box, where you can configure the IDE in detail. Readers can browse a single item and configure it for their interests.

5. after configuring Eclipse, Create the WEB project below. In the package Explorer View panel, right-click, select Dynamic Web Project, and the Create dialog box appears. Enter a name for the project in Project name, enter "Webdemo" here, and the others remain unchanged, as shown in:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://g.hiphotos.baidu.com/album/pic/ Item/a6efce1b9d16fdfa6104320db48f8c5495ee7bed.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "690" width= "640"/>

6.ClickNext, go toJavasettings, here everything stays the same, then clickNext, go toWeb Modulesettings. In the"Context Root:"specified inWebthe name of the application, such asHttp://localhost:8080/WebDemo/index.html, here'sWebdemois localTomcatone of the applications deployed in the container. Here we keepWebdemonot change;"Generate Web Deployment Descriptor"check box is asked if you want to createXml, because inServlet 3.0in whichXmlThe file has become optional, here we keep the check box blank, clickFinish. Such aWebthe project isEclipsethe creation is complete in the. We can be inPackage ExplorerSee the following project structure in the view.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://g.hiphotos.baidu.com/album/pic/ Item/f7246b600c3387446deede9f510fd9f9d72aa02e.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "341" width= "359"/>

wheresrc is used to store the Java class,the WebContent directory contains the page file (HTML file,JSP file,JS Scripts, static images, etc. ).

7. Right-click on the SRC directory, select the New> servlet, and in thepopup Create servlet dialog box, in the Java package: demo, enter helloworldservlet in Class name, and the others remain the same, as shown in:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://f.hiphotos.baidu.com/album/pic/ Item/ca1349540923dd548b46578bd109b3de9c824818.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "523" width= "526"/>

8. Click Next, double- Click "/helloworldservlet" in "URL Mappings:"and change it to "/HW" in the pop-up box,as shown in:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://g.hiphotos.baidu.com/album/pic/ Item/48540923dd54564e4c3114dab3de9c82d0584ff9.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "528" width= "526"/>

9. Click Next, in the dialog box, remove The tick in front of the "constructors from superclass" and "DoPost" checkboxes, and the others remain the same as shown:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://c.hiphotos.baidu.com/album/pic/ Item/cc11728b4710b912cacb051dc3fdfc03934522ce.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "528" width= "526"/>

Click Finishto complete the creationof the Servlet, Helloworldservlet.java opens in the editor, but the red wavy line tells us that there are some errors in the class, The compiler could not compile as shown in:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://a.hiphotos.baidu.com/album/pic/ Item/f31fbe096b63f624eb65cbe08744ebf81a4ca31d.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "403" width= "722"/>

the problem arises because The Servlet API is not in the CLASSPATH of the current project and we need to add it manually. In the project catalog "Webdemo " right-click, select Properties, in the pop-up Project Properties dialog box to the left "Java Build Path", and then on the right to switch to Libraries tab, then click "Add External JARs ..." andnavigate to the Lib directory in the Tomcat installation directory Servlet-api.jar ( If you need to use JSP, check jsp-api.jar at the same time ), click OK. Add the JAR file to the classpath. As shown in the following:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://d.hiphotos.baidu.com/album/pic/ Item/5ab5c9ea15ce36d35e4e78d33af33a87e850b18f.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "552" width= "722"/>

Click OK so thatthe previous error disappears. We add three lines of code in the Doget () method, as follows:

Response.setcontenttype ("Text/html;charset=utf-8");

Response.getwriter (). println ("Hello world!");

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://h.hiphotos.baidu.com/album/pic/ Item/574e9258d109b3de4bf61e8bccbf6c81810a4c8c.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "241" width= "640"/>

after the code has been written, deploy it below. Right-click on the project root "Webdemo" and select "Run as" > "Run on Server". In the main window of the popup box, select "Tomcat v7.0 Server" in the Apache directory , as shown in:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://g.hiphotos.baidu.com/album/pic/ Item/574e9258d109b3de4a99018bccbf6c81800a4c2b.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "684" width= "557"/>

Click Next to navigate to the native installed Tomcat in thenew Window "Tomcat installation directory:" for Tomcat the installation, the others remain the same as shown:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://h.hiphotos.baidu.com/album/pic/ Item/1b4c510fd9f9d72a1f97f5fed42a2834359bbb66.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "684" width= "557"/>

Click Next, everything stays the same, then click Finish. We see the following in the Server view:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://c.hiphotos.baidu.com/album/pic/ Item/80cb39dbb6fd5266da64dbf7ab18972bd5073681.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "378" width= "357"/>

In the browser, enter HTTP://LOCALHOST:8080/WEBDEMO/HW, return, we see the following:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "alt=" http://c.hiphotos.baidu.com/album/pic/ Item/80cb39dbb6fd5266da6bdbf7ab18972bd5073694.jpg "style=" Background:url ("/e/u261/lang/zh-cn/images/ Localimage.png ") no-repeat center;border:1px solid #ddd;" height= "506" width= "722"/>

New Web project in Eclips

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.