Eclipse for Java EE software operation highlights (2), eclipseee

Source: Internet
Author: User

Eclipse for Java EE software operation highlights (2), eclipseee

Before reading this article, make sure you have learned how to build a web project in eclipse. If you have any questions, please refer to the first eclipse software operation series in this series (1)

1. Add a servlet and configure web. xml to test whether the web. xml file can be properly displayed.
:

 


The servlet and web. xml files are as follows.

1 package com. vastsum; 2 3 import java. io. IOException; 4 5 import javax. servlet. servletException; 6 import javax. servlet. http. httpServlet; 7 import javax. servlet. http. httpServletRequest; 8 import javax. servlet. http. httpServletResponse; 9 10 public class HelloServlet extends HttpServlet {11 // override doGet Method 12 @ Override13 protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {14 // TODO Auto-generated method stub15 // output content to the browser 16 resp. getWriter (). write ("test servlet"); 17} 18}View Code

XML Code

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <web-app version = "2.5" 3 xmlns = "http://java.sun.com/xml/ns/javaee" 4 xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" 5 xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee 6 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 7 8 <servlet> 9 <servlet-name> HelloServlet </servlet-name> 10 <servlet-class> com. vastsum. helloServlet </servlet-class> 11 </servlet> 12 13 <servlet-mapping> 14 <servlet-name> HelloServlet </servlet-name> 15 <url-pattern>/hello </url-pattern> 16 </servlet-mapping> 17 18 </web-app>View Code

After adding the file, click "run ".

 

An error occurs after running:

 

2. Solve the following error:
The error occurs because the directory of the generated class file is incorrect. Let's take a look at the class directory under the root directory of the Workspace project.

The generated class file is not under the WEB-INF folder, but under the build folder, next we will do the following settings.
First, delete the published MyWeb.

 

Then, set the runtime and release it to the corresponding directory of the tomcat server ,:

Modify the preceding two parameters to publish the project to the tomcat server.

Finally, select the project, right-click Build Path-> Configure Build Path, and then:

 

This is to control the Java file generation to the correct directory.

3. After modifying the folder location. Run the web project again.
Enter http: // localhost: 8080/MyWeb/hello in the address bar of the browser to access the website normally.

**************************************** ******************************
Solutions to some common problems
1. Creating a web project with Eclipse does not automatically generate web. xml
Click to create a project:

 

 

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.