[Solved] SpringMVC Run Error: SEVERE-Servlet.service() for servlet jsp threw exception

Today, I was learning spring MVC. Everything was difficult at the beginning. I didn’t expect it to be so difficult. The most basic Hello World was trapped for half an hour. The main problem was that Tomcat 10 version didn’t adapt to and Maven relied on. The error was: servlet. Service () for servlet JSP thread exception Java. Lang. NullPointerException , and the following is the specific solution

Read the original text

At the beginning of writing dependency, I found that groupid in the book was javax , and I had suffered such a loss before. In order to adapt it to my Tomcat 10, I changed it to Jakarta . As a result, when writing controller , the method can only recognize javax , and I can’t change the source code again, There is no way to replace dependence with this

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.3</version>
</dependency>

Not surprisingly, when the Tomcat server is executed, it always reports an error saying that org.springframework.web.servlet.dispatcherservlet in the configuration file is not a servlet, so there is no way but to change the method

I thought Maven could play Tomcat plug-in and paste the dependent code immediately

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
        </plugin>
    </plugins>
</build>

Continue to run and report an error: servlet. Service () for servlet JSP thread exception Java. Lang. NullPointerException , go to stackoverflow and say that the range must be set to provided , and then run to display it. Later, switch back to normal tomcat operation with a try state, but the result is still not good

PS: finally switched back to Tomcat version 9.052


Read More: