Today, I am running the JSP of a book on Tomcat (7.0.8 ).Source codeThe following error occurs:
1 Org. Apache. Jasper. jasperexception: Unable to compile class for JSP:
2
3 An error occurred at line: 23 In the generated Java File
4 The method getjspapplicationcontext (servletcontext) is undefined for the Type jspfactory
5
6 Stacktrace:
7 Org. Apache. Jasper. compiler. defaulterrorhandler. javacerror (defaulterrorhandler. Java: 95 )
8 Org. Apache. Jasper. compiler. errordispatcher. javacerror (errordispatcher. Java: 330 )
9 Org. Apache. Jasper. compiler. jdtcompiler. generateclass (jdtcompiler. Java: 457 )
10 Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 367 )
11 Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 345 )
12 Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 332 )
13 Org. Apache. Jasper. jspcompilationcontext. Compile (jspcompilationcontext. Java: 594 )
14 Org. Apache. Jasper. servlet. jspservletwrapper. Service (jspservletwrapper. Java: 342 )
15 Org. Apache. Jasper. servlet. jspservlet. servicejspfile (jspservlet. Java: 391 )
16 Org. Apache. Jasper. servlet. jspservlet. Service (jspservlet. Java: 334 )
17 Javax. servlet. http. httpservlet. Service (httpservlet. Java: 722 )
18
19
View the Tomcat log and find the following error:
1 Severe: failed to initialize end point associated with protocolhandler [ Http-apr-8088" ]
2 Java. Lang. Exception: Socket bind failed: [ 730048 ] Only one usage of each socket address (Protocol/network address/port) is normally permitted.
3 At org.apache.tomcat.util.net. aprendpoint. BIND (aprendpoint. Java: 408 )
4 At org.apache.tomcat.util.net. abstractendpoint. INIT (abstractendpoint. Java: 511 )
5 At org. Apache. Coyote. abstractprotocolhandler. INIT (abstractprotocolhandler. Java: 345 )
6 At org. Apache. Catalina. connector. connector. initinternal (connector. Java: 910 )
7 At org. Apache. Catalina. util. lifecyclebase. INIT (lifecyclebase. Java: 101 )
8 At org. Apache. Catalina. Core. standardservice. initinternal (standardservice. Java: 559 )
9 At org. Apache. Catalina. util. lifecyclebase. INIT (lifecyclebase. Java: 101 )
10 At org. Apache. Catalina. Core. standardserver. initinternal (standardserver. Java: 778 )
11 At org. Apache. Catalina. util. lifecyclebase. INIT (lifecyclebase. Java: 101 )
12 At org. Apache. Catalina. startup. Catalina. Load (Catalina. Java: 572 )
13 At org. Apache. Catalina. startup. Catalina. Load (Catalina. Java: 595 )
14 At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
15 At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39 )
16 At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25 )
17 At java. Lang. Reflect. method. Invoke (method. Java: 597 )
18 At org. Apache. Catalina. startup. Bootstrap. Load (Bootstrap. Java: 263 )
19 At org. Apache. Catalina. startup. Bootstrap. Main (Bootstrap. Java: 431 )
In the beginning, I thought there was a problem with server configuration. I searched the internet and found that it was caused by multiple Tomcat operations, or the JSP code was faulty.
However, I tried Tomcat's self-built JSP, which is running well.
Therefore, Tomcat should have no configuration problems.
Later I found the source of this book.CodeThe build. xml file in is set as follows:
1 < Property Environment = "Env" />
2 < Property Name = "Src" Value = "WEB-INF/src" />
3 < Property Name = "Classes" Value = "WEB-INF/classes" />
4 < Property Name = "Lib" Value = "WEB-INF/lib" />
5 < Property Name = "Dist" Value = "Dist" />
6
7 < Path ID = "Task. classpath" >
8 < Pathelement Location = "$ {Classes }" />
9 < Pathelement Location = "$ {Lib }" />
10
11 <! --
Tomcat 5.0.16 Servlet 2.4 API -->
12 < Pathelement Location = "$ {Lib}/servlet-api.jar" />
13
14 <! --
Tomcat 5.0.16 JSPs 2.0 API -->
15 < Pathelement Location = "$ {Lib}/jsp-api.jar" />
16
17 </ Path >
This tomcat version is older than mine.
After that, replace the two jar packages in the lib directory of Tomcat, and then complete the process. JSP can be compiled and run.
To sum up,"Unable to compile class for JSP"Eight is related to the" jsp-api.jar "used for compilation.