解决"HttpServlet cannot be resolved to a type "出现的原因

版权声明:本文为博主原创文章,转载请附上博文链接。感谢合作! https://blog.csdn.net/Angelia620/article/details/86528765

每次需要Tomact工作的时候,都会出现各种的问题。每次都需要重新建一个Tomact服务器的时候,就会出现各种各样的错误问题提示,下面是我对这些错误的汇总。

错误一:"HttpServlet cannot be resolved to a type "

原因一:没有添加servlet-api.jar包

这种错误是因为在Servlet项目中,没有添加servlet-api.jar包,需要在Tomact的安装目录下的lib文件中找到servlet-api.jar添加到项目中去。

添加步骤:点击项目名称—>右键—>点击最下面的"Properties"—>点击"Java Build Path"—>找到"Libraries"—>点击"Add External JARs....."—>找到Tomact的安装目录—>打开lib文件—>找到"servlet-api.jar"包—>点击添加即可。

原因二:Eclipse是刚刚安装的,还没有配置服务器运行环境

具体的安装与配置请查看Eclipse下新建Tomact服务器

错误二: How to Fix Installation of Apache Tomcat Server Issue – Blank Server Name Field?

  • 关闭Eclipse
  • 在 {workspace-directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings
  • 删除以下两个文件:org.eclipse.wst.server.core.prefs org.eclipse.jst.server.tomcat.core.prefs
  • 重启Eclipse

错误三:Could not load the Tomcat server configuration at apache-tomcat-9.0.13\conf. The configuration may be corrupt or incomplete.

扫描二维码关注公众号,回复: 5007872 查看本文章

原因:我修改了server.xml文件中内容,使用了中文,出现了乱码问题

解决方法:

  • 找到Tomact服务器的安装目录
  • 打开conf文件
  • 找到server.xml文件,用编译器打开
  • 修改该文件的保存方式(UTF-8方式保存)

猜你喜欢

转载自blog.csdn.net/Angelia620/article/details/86528765
今日推荐