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:
- Spring boot project running error: Servlet.service () for servlet [dispatcherServlet] threw exception
- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request p
- An error was reported when springboot connected to redis Servlet.service () for servlet [dispatcherServlet] in context with path [] threw e
- Maven project running servlet jump JSP error: HTTP status 500 – unable to compile class for JSP
- The spring boot set appears in the stand-alone version of redis Servlet.service () for servlet [dispatcherServlet] in context with path [] thr
- Servlet jump to JSP page 404 error
- The solution to the problem that the method of interacting with database in the servlet class is invalid after the servlet submits 404, 500 refresh and becomes 404, and after connecting to the data pool
- Exception of browser accessing servlet404
- 404 exception in servlet operation
- Unable to access javax.servlet.servletexception [How to Solve]
- maven_ Unable to create servlet file under Java Web project
- Eclipse create servlet file error
- [spring] start error: nosuchmethoderror: javax.servlet.http . HttpServletResponse.getStatus () I
- 404 error in browser accessing Servlet
- Problems of accessing servlet display 404 on MyEclipse
- Possible causes and solutions of 404 problems in accessing servlet pages
- Error 500: javax.servlet.ServletException : srve0207e: Solutions
- When idea writes JavaWeb, it can’t find servlet
- Servlet error: no interface expected here
- Failed to instantiate org.mybatis.spring.SqlSessionTemplate Constructor threw exception