通过maven创建一个web项目后,已将src/main下java进行Mrak Dirctory as 为 Source Root,但右键仍无法创建Servlet。经过查找各资料,找到以下将诶决方案
1:在项目pom.xml中添加以下代码;
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
设置后IDEA提示版本报错,没有成功。
2:同样在xml中添加如下代码:
<facet type="web" name="Web"> <configuration> <descriptors> <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/WebContent/WEB-INF/web.xml" /> </descriptors> <webroots> <root url="file://$MODULE_DIR$/WebContent" relative="/" /> </webroots> </configuration> </facet>
仍未成功
3:
我们打开.iml文件,在这里
添加如下
<root url="file://$MODULE_DIR$/src/main/java" />
同样未成功;
4:成功,操作如下
点击File-Project Structure..