解决在eclipse中创建maven版web工程出现的问题:web.xml is missing and <failOnMissingWebXml> is set to true,添加jsp文件报错

      eclipse创建maven版web工程时,pom.xml文件报错:web.xml is missing and <failOnMissingWebXml> is set to true,如下图。

        这是因为web项目必须要有核心配置文件web.xml,可以手动在src/main/webapp目录下创建,也可以使用以下方式创建【推荐】,这种方式可以在src/main/webapp目录下生成其他文件夹,如WEB-INF/lib。

        【推荐操作】右击项目名 -> Properties -> Project Facets  将Dynamic Web Module的勾去掉,点击Apply,再重新勾上,点击下方出现的Further configuration available(之前没有),再选择生成的目录即可生成web.xml,其中Content directory改为:src/main/webapp,如下图。

         上述操作后,原来空的src/main/webapp路径下出现了web.xml和其他目录结构,如下图。

         紧接着右键webapp新建一个jsp文件时,会报错:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path,如下图。

因为找不到javax.servlet.http.HttpServlet类,两种处理方式,如下。

        (1)eclipse的做法,添加tomcat运行时环境

        (2)maven工程的做法,添加maven依赖【推荐】

        方式一:添加Apache-tomcat运行时环境,里边有所需jar包。

       方式二:在maven工具的pom.xml文件中添加所需依赖即可。

<dependencies>
  	<dependency>
  		<groupId>javax.servlet</groupId>
  		<artifactId>servlet-api</artifactId>
  		<version>2.5</version>
  		<scope>provided</scope>
  	</dependency>
  	<dependency>
	    <groupId>javax.servlet.jsp</groupId>
	    <artifactId>javax.servlet.jsp-api</artifactId>
	    <version>2.3.1</version>
	    <scope>provided</scope>
	</dependency>
</dependencies>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值