First, the problem description:
First explain the development environment, JDK is 1.8, the IDE is the Eclipse 4.7,web server is Tomcat 9.0,maven is 3.5.0, set up the environment after the input command Tomcat:run, The org.apache.jasper.JasperException:Unable to compile class for JSP error is then reported.
Second, the analysis of the problem:
(1) Can not be compiled should not be imported SERVLET-API, JSP-API package, and then add Servlet-api, Jsp-api package in the Pom file, in order to prevent packet conflict, need to change <scope> to provided.
1 <Dependency>2 <groupId>Javax.servlet</groupId>3 <Artifactid>Servlet-api</Artifactid>4 <version>2.5</version>5 <Scope>Provided</Scope>6 </Dependency>7 <Dependency>8 <groupId>Javax.servlet</groupId>9 <Artifactid>Jsp-api</Artifactid>Ten <version>2.0</version> One <Scope>Provided</Scope> A </Dependency>
Add later or not, and then start looking for Niang, start a second solution.
(2) Eclipse defaults to its own JRE, which requires us to change to a downloaded JDK, in window->preference->java->installed Add your own downloaded JDK to JREs and remove the JRE that comes with eclipse.
After running or not, after the majority of Baidu is similar to the solution, all can not, had to slowly explore, from the project to run a careful inspection, and finally found the problem.
The original Maven used by default is TOMCAT6, and I use JDK1.8,TOMCAT6 cannot be used with JDK1.8. Just move the Tomcat version to the line.
(3) using Maven's TOMCAT7 plugin: Add the code to the Pom file:
1 <Build>2 <Plugins>3 <plugin>4 <groupId>Org.apache.maven.plugins</groupId>5 <Artifactid>Maven-compiler-plugin</Artifactid>6 <version>3.1</version>7 <Configuration>8 <Source>1.8</Source>9 <Target>1.8</Target>Ten <encoding>Utf-8</encoding> One </Configuration> A </plugin> - <plugin> - <groupId>Org.apache.tomcat.maven</groupId> the <Artifactid>Tomcat7-maven-plugin</Artifactid> - <version>2.2</version> - </plugin> - </Plugins> + </Build>
Then you can change the MAVEN command to Tomcat7:run.
Maven project cannot compile JSP workaround: Unable to compile class for JSP