解决idea的maven工程出现:org.apache.jasper.JasperException: Unable to compile class for JSP

本来就是想试验一下,新建一个简单的maven工程,实现一个简单的Servlet跳转jsp的功能。没想到遇到了很棘手的bug:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	com.itheima.servlet.MyServlet.doGet(MyServlet.java:18)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.
Apache Tomcat/6.0.29```

本来是在idea中先clean,然后运行tomcat:run

看了一下bug信息,运行的是Apache Tomcat 6.0.29,那么问题可能就是在这个tomcat版本还有和jdk版本上吧:

于是去项目下的pom.xml文件中去配置:

在进行如下的配置:


        
          org.apache.tomcat.maven
          tomcat7-maven-plugin
          2.2
          
            8888
          

        
        
          org.apache.maven.plugins
          maven-compiler-plugin
          
            1.8
            1.8
            UTF-8

          
        
        

其中tomcat端口可以不用设置设置为8888。

这里我其实先设置了,scope标签:意味限定作用域,防止出现两个同名servlet和jsp包报错。


      javax.servlet
      servlet-api
      2.5
      provided
    
    
    
      javax.servlet.jsp
      jsp-api
      2.0
      provided
    
    

做完以上配置后,开始运行项目:
双击clean,然后再点击那个M小窗口
解决idea的maven工程出现:org.apache.jasper.JasperException: Unable to compile class for JSP_第1张图片
打开窗口后,输入:

tomcat7:run

如下图所示:
解决idea的maven工程出现:org.apache.jasper.JasperException: Unable to compile class for JSP_第2张图片

然后就可以跳转啦~
解决idea的maven工程出现:org.apache.jasper.JasperException: Unable to compile class for JSP_第3张图片

希望可以对大家有所帮助。

你可能感兴趣的:(Java,Bug,maven,Java,Jsp,maven,web,tomcat)