通過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..