新建Maven項目Webapp下index.jsp報錯

最近用MyEclipse新建了一個maven項目,新建完成index.jsp頁面就報錯了,先把錯誤信息貼出來看看:
這裏寫圖片描述
後來就找資料,結果發現兩種解決辦法,希望可以幫助用得上的人!
第一種:直接在pom.xml文件中添加jar包支持

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

完整的如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.chen</groupId>
    <artifactId>chen</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>chen Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>chen</finalName>
    </build>

</project>

保存發現,index.jsp 不再報錯。

第二種方式:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.how2java.tmall</groupId>
    <artifactId>chen</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>chen Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
<!--        這裏把第一種方式註釋掉 -->
<!--        <dependency> -->
<!--            <groupId>javax.servlet</groupId> -->
<!--            <artifactId>javax.servlet-api</artifactId> -->
<!--            <version>3.1.0</version> -->
<!--        </dependency> -->
    </dependencies>
    <build>
        <finalName>chen</finalName>
    </build>

</project>

右鍵項目,先選擇“Build Path”,再選擇“configure build path”,按着圖示選擇箭頭所指的MyEclipse Server Library
這裏寫圖片描述
再點下 Next
這裏寫圖片描述
選擇Apache Tomcat ,最後點擊Finish
這裏寫圖片描述
最後index.jsp 已經不再報錯。
《完》

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章