这是我的JSP:
<HTML>
<BODY >
path : <%= application.getContextPath() %>
</BODY>
</HTML>
该文件在Tomcat7和Tomcat6中是正确的,但是当我在Cpanel托管的Tomcat 5.32中请求JSP页面时,出现以下异常:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 3 in the jsp file: /cal2.jsp
The method getContextPath() is undefined for the type ServletContext
1: <HTML>
2: <BODY>
3: path : <%= application.getContextPath() %>
4: </BODY>
5: </HTML>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:328)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:307)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:309)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:72
这个问题是怎么引起的,我该如何解决?
最佳答案
在规范的2.5版中,已将getContextPath()
方法添加到ServletContext
中,但是Tomcat 5仅实现2.4。但是,request.getContextPath()
做同样的事情。
关于java - 对于ServletContext类型,未定义方法getContextPath(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7448539/