Eclipse 不会自动将 servlet 添加到 web.xml?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5377946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 20:04:34  来源:igfitidea点击:

Eclipse doesn't automatically add servlets to web.xml?

eclipseservletsautomation

提问by Evgeni Dimitrov

I used to use Eclipse Galileo, but now I have Helios. Galileo used to automatically add my servlets to web.xml, but in Helios I have to do this myself.

我曾经使用 Eclipse Galileo,但现在我有了 Helios。Galileo 曾经自动将我的 servlet 添加到web.xml.

Is there something I can configure to make this automatic again?

有什么我可以配置的东西,让它再次自动?

采纳答案by BalusC

This hasn't been changed. Most likely you have used New > Classinstead of New > Servletto create the servlet.

这没有改变。您很可能使用New > Class而不是New > Servlet来创建 servlet。

回答by Alexander Sidikov Pfeif

this post will help you ..

这篇文章会帮助你..

https://stackoverflow.com/a/14854907/1847899

https://stackoverflow.com/a/14854907/1847899

"Tomcat 7 is a Servlet 3.0 compatible container. Since Servlet 3.0, the servlets can be configured by @WebServlet annotation on the class without the need for a web.xml configuration entry."

“Tomcat 7 是一个兼容 Servlet 3.0 的容器。从 Servlet 3.0 开始,servlet 可以通过类上的 @WebServlet 注释进行配置,而无需 web.xml 配置条目。”

回答by rakesh.ranjan673

You need to change some settings on the project:

您需要更改项目的一些设置:

  1. Create dynamic project
  2. Right-click on name of dynamic project
  3. Create servlet name and click Next(not `Finish)
    • The URL mapping will show
  4. Click on Addand give it the name you used in web.xml (like /mohan)
    • By default it will be name of servlet
  5. Click on remove
  6. Remove the default URL mapping name
  1. 创建动态项目
  2. 右键单击动态项目的名称
  3. 创建 servlet 名称并单击Next(不是“完成”)
    • URL 映射将显示
  4. 单击Add并为其指定您在 web.xml 中使用的名称(如 /mohan)
    • 默认情况下,它将是 servlet 的名称
  5. 点击移除
  6. 删除默认的 URL 映射名称

Now it should work.

现在它应该可以工作了。

回答by user4034442

you dont need to worry about that Tomcat 7 is a Servlet 3.0 compatible container. Since Servlet 3.0, the servlets can be configured by @WebServlet annotation on the class there is no need for a web.xml configuration entry.If you are still confused just change the "dynamic web module version" to 2.5 instead of 3.0 at this point... new-> dynamic web project. then you can see that your servlets will be configured in web.xml automatically

您无需担心 Tomcat 7 是一个兼容 Servlet 3.0 的容器。从 Servlet 3.0 开始,servlet 可以通过类上的 @WebServlet 注释进行配置,不需要 web.xml 配置条目。如果您仍然感到困惑,此时将“动态 Web 模块版本”更改为 2.5 而不是 3.0 ... 新建-> 动态 Web 项目。然后您可以看到您的 servlet 将自动在 web.xml 中配置